So my dilemma is that I have a menu for 2 games, both within their respective switch statement/cases. The code works, but it'll close the game once it's done. I can't for the life of me figure out how to loop back to the main menu that I made to select the games.
#include<iostream>
#include<string>
#include<cstdlib>
#include<ctime>
#include<iomanip>
usingnamespace std;
int main()
{
string name;
int choice; //the choices for the menu
char sym; //part of the menu
int number = rand() % 10 + 1; //sets number to a random number between 1-10
int digit; // part of the math game
bool menu = true;
int guessNum; //number that user guesses
int i; //loop variable
bool guessRight = false;
char answer = 'y';
//questions omitted
while (menu){ //start of loop and will come back here after each game finishes
cout << setfill(sym) << setw(55);
cout << "\n";
cout << "\t Welcome," << ' ' << name << endl;
cout << "Please choose a number from the following options:" << endl; //Gives the user the options to input using numbers.
cout << "\n";
cout << "\t1. Play the math game!" << endl;
cout << "\t2. Play the guessing game!" << endl;
cout << "\t3. Exit" << endl;
cout << setfill(sym) << setw(55);
cout << "\n";
cin >> choice; //The user gets to input numbers 1-3 at this point
switch (choice)
{
case 1:
//Math game here
break;
case 2:
//random number game here
break;
case 3: //exits the program
cout << "I guess we're done here." << endl;
return 0;
}
}
}
I've omitted the games themselves, but I'm confused as to how to loop back to the main menu from both games. I suspect that I have to inset a do-while loop but I'm not sure how to go about doing that. I appreciate any advice!