Hi I am fairly new to c++ and am just writing some codes for practice and I was wondering if there is a command I can use to move the program back to a previous line?
For example if I had asked the user to input a value from 1 to 10 and they entered 11 or "f" I know I can say sorry that is an unacceptable value but Is there some way to go back to the original question or is my only option to close and restart the program?
this is going to be mean but i can't resist. nope all of the brilliant people that made c++ decided your program can only run in one direction one time. now in all seriousness look up loops
int value = 0;
while(value < 1 || value > 10) // this will continue to loop until an acceptable integer value is entered
{
cout << "Enter a positive integer between 1 and 10: ";
cin >> value;
if(value < 1 || value > 10) // this will deal with out of range integers
{
cout << "That is not an acceptable value, try again...\n";
}
if(!cin) // this will deal with non-integer entries
{
cin.clear(); // reset cin error states/flags
cin.sync(); // flush cin buffer
}
}