Switch statement

Aug 10, 2015 at 2:59am
I want to know how to do Switch statement? When user enters Y it will exit and if user enter N, the program will redisplay the menu. Im stucked here.
Hence this is the sample output desired.
WARNING! Queue is not empty. Proceed? [Y/N]: Y


Aug 10, 2015 at 3:57am
Here's the format

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//declare variable
char decision = ' ';

//determine output
switch (decision)
{
case 'Y':
    //put output code here...
    break;
case 'N':
    //put output code here...
    break;
default:
    /*put things like error messages
      in here -- chosen if no other 
      match is found*/
} //end switch 
Last edited on Aug 10, 2015 at 4:01am
Aug 10, 2015 at 6:47am
Lbkulinski


thank you my friend.
Aug 10, 2015 at 6:58am
No problem
Aug 10, 2015 at 10:59am
We can also apply this code:

#include<iostream>
using namespace std;
#include<conio.h>
int main() {
string a;
cin>>a;
switch (string(a)) {
case "Option 1":
cout<<"It pressed number 1"<<endl;
break;
case "Option 2":
cout<<"It pressed number 2"<<endl;
break;
case "Option 3":
cout<<"It pressed number 3"<<endl;
break;
default:
cout<<"She put no choice"<<endl;
break;
}
return 0;
}
Aug 10, 2015 at 11:29am
camycent wrote:
We can also apply this code:
No, that doesn't work with C/C++.
Topic archived. No new replies allowed.