I am sure that there is a way of making this simpler, but because i'm new i'm not sure how. I want it to loop to the menu everytime the option 2 is entered, and i want it to loop to the question about whether it is the right option if they enter a number bigger than 2. I would also like some help on this.Code:#include <iostream>;
#include <cstdlib>;
using namespace std;
int menu()
{
int choice;
cout << " **** Menu ****" << endl << endl; //States the options on the menu
cout << "(1) Play Game." << endl;
cout << "(2) Options." << endl;
cout << "(3) Multiplayer." << endl;
cout << "(4) Quit." << endl << endl;
cout << ": ";
cin >> choice; //enter there choice, 1,2,3 or 4
return choice;
}
int main()
{
int choice = menu(), i, second;
cout << "You chose option " << choice << endl; //tells the user their choice
cout << "Is this correct? If yes click 1, if no click 2. " << endl; //asks them if it is correct (1) or not (2)
cout << " (1)"<<endl;
cout << " (2)"<<endl;
cin>>second; //they enter their choice 1 or 2
if (second==1){ // if they enter 1, it says that they can continue
cout<< "Click to continue."<<endl;
cin>>i
;
return 0;
}
else if (second==2) // if they enter 2, it gives them the menu again
{
cout << "Try again then."<<endl;
{int choice = menu(), i, second;
cout << "You chose option " << choice << endl;
cout << "Is this correct? If yes click 1, if no click 2. " << endl;
cout << " (1)"<<endl;
cout << " (2)"<<endl;
cin>> second;
}
return 0;
}
else (second>2); // if they enter a number bigger than 2, it tells them that it is invalid
{
cout<<"You have not entered a valid choice."<<endl;
cin>>i;
return 0;
}
return second;
}