I am having trouble figuring out how to set up Switch statements to display a caller's choice of Dr.'s. Most of the code works as it should, but I still can't figure out how to make the code display the Dr.'s name after a selection is made in the first Switch statement. I'm sure it's something simple I'm overlooking, so any help would be appreciated...
switch (choice)
{
case 1: cout << "Press 1 for making an appointment with Dr. Green." << endl;
cout << "Press 2 for making an appointment with Dr. Fox." << endl;
cout << "Press 3 for making an appointment with Dr. Davis" << endl;
cin >> choice;
break;
cout << "Press any other key to talk to an operator" << endl;
case 2: cout << "Billing questions" << endl;
break;
case 3: cout << "Talking to a nurse" << endl;
break;
default: cout << "Talking to an operator" << endl;
cin >> choice;
}
switch (drChoice)
{
case 1: cout << "Making an appointment with Dr. Green." << endl;
case 2: cout << "Making an appointment with Dr. Fox." << endl;
case 3: cout << "Making an appointment with Dr. Davis" << endl;
cin >> drChoice;
break;
cout << "Press any other key to talk to an operator" << endl;
}
#include<iostream>
usingnamespace std;
int main ()
{
int choice = 0;
int drChoice = 0;
cout << "Enter your choice [1, 2, 3]: ";
cin >> choice;
switch (choice)
{
case 1: cout << "Press 1 for making an appointment with Dr. Green." << endl;
cout << "Press 2 for making an appointment with Dr. Fox." << endl;
cout << "Press 3 for making an appointment with Dr. Davis" << endl;
cin >> choice; // This should be drChoice
break;
cout << "Press any other key to talk to an operator" << endl; //What is this? It's not inside any of the cases
case 2: cout << "Billing questions" << endl;
break;
case 3: cout << "Talking to a nurse" << endl;
break;
default: cout << "Talking to an operator" << endl;
cin >> choice; // This does nothing.
}
switch (drChoice)
{
case 1: cout << "Making an appointment with Dr. Green." << endl;
case 2: cout << "Making an appointment with Dr. Fox." << endl;
case 3: cout << "Making an appointment with Dr. Davis" << endl;
cin >> drChoice; // Again, this does nothing
break;
cout << "Press any other key to talk to an operator" << endl; // Again, this is outside any case choices
}
system ("pause");
return 0;
}
Also, if you don't know how to use code tags, just put ["code"] at the start of your code and ["/code"] at the end (without the quotes).
Thank you! All is working fine now. I'm not familiar with the term "code tags" (my professor doesn't use this term), but I added some int named constants to fix the problem, so I'm assuming that's what you meant. :-)