I'm trying to write an extremely simple program, but I can't figure out how to loop back to a certain point... This is what I have:
Code:
#include <iostream>
using namespace std;
int main()
{
int a; {
cout<<"Please type a number that is less than 5: \n";
cin>> a;
cin.ignore();
}
if ( a < 5 ) {
cout<<"Correct!\n";
cin.get();
}
else if ( a > 5 ) {
cout<<"Incorrect, try again...\n";
return main();
}
else {
cout<<"I said LESS THAN 5... Try again.\n";
return main();
}
//I only want it to loop back to here, instead of back to the beginning...
int b; {
cout<<"Please solve this equation for variable Y: y=2x3+7 \n";
cin>> b;
cin.ignore();
}
if ( b == 13 ) {
cout<<"Correct!\n";
cin.get();
}
else if ( b > 13 ) {
cout<<"Nope, Try again...\n";
return main(); //This is where I would want it to stop and go back
}
else ( b < 13 ); {
cout<<"Nope, Try again...\n";
return main(); //This is also where I would want it to stop and go back
}