Menu driven with switch class

Hey Guys! I'm kind of new to coding, and I apologize beforehand for my slowness.
So i'm trying to make a menu driven code for practice. I have it so the user puts in the number and chooses something from the vending machine, but I want an out option, like a yes or no where the program asks you if you want to choose again this is what i have so far.

#include <iostream>


using namespace std;

int value;
int main() {
cout << "welcome to the vending machine! please choose from one of the following!" << endl;
cout << " press 1 for coke \n press 2 for sprite \n press 3 for crush \n press 4 for water \n press 5 for juice"<<endl;

while (value != -1){
cin >> value;
switch (value) {
case 1:
cout << "you've chosen coke" << endl;
break;
case 2:
cout << "you've chosen sprite" << endl;
break;
case 3:
cout << "you've chosen crush" << endl;
break;
case 4:
cout << "you've chosen water" << endl;
break;
case 5:
cout << "you've chosen juice" << endl;
break;
default:
cout << "That's not one of the options" << endl;
break;
}
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
for(;;){
cin >> value;
switch (value) {
case 1:
cout << "you've chosen coke" << endl;
break;
case 2:
cout << "you've chosen sprite" << endl;
break;
case 3:
cout << "you've chosen crush" << endl;
break;
case 4:
cout << "you've chosen water" << endl;
break;
case 5:
cout << "you've chosen juice" << endl;
break;
default:
cout << "That's not one of the options" << endl;
break;
}

char YesNo;
cout << "Choose again? (Y : 'Yes') : "; 
if(cin >> YesNo && toupper(YesNo) == 'Y'); else break; 
} 



Topic archived. No new replies allowed.