nested switches

cout<< " Welcome to the phone company menu \n"
<< "For information about your account press "<< phone_account_info<< endl
<< "For emergency phone call press "<< emergency_phone_call<< endl
<< "just to talk press " << just_to_talk << endl
<< "enter your selection now\n";
cin>> selection;
{

switch (selection)
{
case '1':
{ cout<<"you chose " << phone_account_info << "for phone account info\n"
<< "for over billing problem press " << over_billing <<endl
<< "for specific charge issue " << specific_charge_issue <<endl
<< "to go to main menu press " << go_home << endl
<< "to exit program press " << exit << endl;
cin>> selection;

switch(selection)
{
case '1': cout<< "you chose " << over_billing<< endl;
break;

case '2': cout<< "you chose " << specific_charge_issue<< endl;
break;

case '8': cout<< "you chose " << go_home<< endl;
break;

case '9': cout<< "you chose " << exit<< endl;
break;}

break;}
case '2':
break;
}
}



all i can get it to do is run the first cout statement then any input after that just starts it over from the begining.
What is 'selection' defined as?

Is it a char or an int?

It would need to be a char for this to work, since you are using the character '1' and not the integer 1.
Last edited on
int selection;
do
{
cout<< " Welcome to the phone company menu \n"
<< "For information about your account press "<< phone_account_info<< endl
<< "For emergency phone call press "<< emergency_phone_call<< endl
<< "just to talk press " << just_to_talk << endl
<< "enter your selection now\n";
cin>> selection;
{

switch (selection)
{
case '1':
{ cout<<"you chose " << phone_account_info << "for phone account info\n"
<< "for over billing problem press " << over_billing <<endl
<< "for specific charge issue " << specific_charge_issue <<endl
<< "to go to main menu press " << go_home << endl
<< "to exit program press " << exit << endl;
cin>> selection;

switch(selection)
{
case '1': cout<< "you chose " << over_billing<< endl;
break;

case '2': cout<< "you chose " << specific_charge_issue<< endl;
break;

case '8': cout<< "you chose " << go_home<< endl;
break;

case '9': cout<< "you chose " << exit<< endl;
break;}

break;}
case '2':
break;
}
}
}

while(selection != exit);









system("PAUSE");
return EXIT_SUCCESS;
}

if i just had case 1: would it work or does it always need to be a char
thanks that worked
Topic archived. No new replies allowed.