Reputation: 29
I'm writing a little c++ console program to improve my programming and to begin a portfolio. My question is:
How do I continue my story after the else
statement?
Part of the code I have is:
else {
cout << "That's not an answer mate!" << endl;
}
How do I make the program NOT exit, but ask for a new input from the user?
Thanks in advance!
Upvotes: 0
Views: 97
Reputation: 1
You can use goto
statement
example:
Condition1: cout<<"Enter age: ";
cin>>age;
if (age>18){
cout<<"Welcome"<<endl;
//same code...
}
else{
goto Condition1;
}
this is the same method as using loops
Upvotes: 0
Reputation: 36463
You wrap the qustioning code in a while
and keep asking until the "correct" answer is given:
bool error;
do {
error = false;
//some code here..
//if statement to check..
else
{
cout << "That's not an answer mate!" << endl;
error = true;
}
}while(error);
Upvotes: 2