I was assigned to write a program in C++ to take user input, perform some calculation, then present the user with the information after calculations were performed.
The specifics of the program are not needed, since my question is in reference to input validation specifically. What is considered to be better practice / more practical for validating multiple user inputs?
- Using a
while
loop inint main()
to catch bad input after everycin
statement
OR
- Passing input to a function with 1
while
loop to validate the input, the return the input back.
I am fairly new to programming in general, and have only been working in C++ for a few weeks, and my greenhorn instincts would tell me to create a few while
loops in int main()
and call it a day. Something tells me a function would be a better idea, because, you know, object orientation.
Thanks in advance. - Wes