Menu Chooser loop

How would I use a do while loop or a while loop to only repeat vases 1-3, and default; and exit when case 4 is picked.

// Menu Chooser
// Demonstrates the switch statement

#include <iostream>
using namespace std;

int main()
{
cout<<"Difficulty levels\n\n";
cout<<"1 - Easy"<<endl;
cout<<"2 - Normal"<<endl;
cout<<"3 - Hard"<<endl;
cout <<"4-Exit"<<endl;


int choice;
cout<<"Choice: ";
cin>>choice;

switch (choice)
{
case 1:
cout<<"You picked Easy."<<endl;
break;
case 2:
cout<<"You picked Normal."<<endl;
break;
case 3:
cout<<"You picked Hard."<<endl;
break;
case 4:
cout<< "You picked to Exit."<<endl;
break;

default:
cout<<"You made an illegal choice."<<endl;
}
return 0;
}
Last edited on
closed account (LA48b7Xj)
1
2
3
4
5
6
7
8
9
10
11
int choice = 0;
while(choice != 4)
{
    cout<<"Choice: ";
    cin>>choice;

    switch (choice)
    {
        /* case statements */
    }
}
Topic archived. No new replies allowed.