My code is nearly perfect with exception of two issues: 1) When 1, 2, or 3 is selected in the second switch statement, the correct doctor's name displays (i.e, "Making an appointment with Dr. Green.") But, to get out of the program, you have to select a character or a number other than 2 or 3 and then press enter to get the message, "Press any key to continue..." 2) I also have a problem with the "Press any other key to talk to an operator" not working correctly in the first switch statement (after a 1, 2, or 3 is entered). I've been working on this program all day and it's driving me crazy (errrrrrr), so any assistance correcting these two problems would be appreciated. :-)
int main ()
int choice = 0;
int drChoice = 0;
int choice1 = 1;
int choice2 = 2;
int choice3 = 3;
cout << "Enter your choice [1, 2, 3]: ";
cin >> 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;
cout << "Press any other key to talk to an operator" << endl;
cin >> drChoice;
case 2: cout << "Billing questions" << endl;
case 3: cout << "Talking to a nurse" << endl;
default: cout << "Talking to an operator" << endl;
case 1: cout << "Making an appointment with Dr. Green..." << endl;
cin >> choice1;
case 2: cout << "Making an appointment with Dr. Fox..." << endl;
cin >> choice2;
case 3: cout << "Making an appointment with Dr. Davis..." << endl;
cin >> choice3;
I was advised by another commenter (freddy92) to put it there (cin >> drChoice;), and if I remove it, it screws the whole program up. Also moving/copying the "default: cout << "Talking to an operator" << endl;" to the second switch doesn't resolve the problem I'm having, but I appreciate your input.
Could you please post the program you created? I tried to follow your instructions (move the lines to where you said, etc.) but the program's coming out all screwy (eyes are buggin' out of my head after 10 hours of trying to fix this program). Hope you don't mind...
Thank you so much, leftcoast! Problem is, we have yet to learn about "\n", so I'm sure my professor would bust me on that. However, I wish I COULD use your program because the output is so much neater. I assume I'll learn more about using "\n" in the not-too-distant future. However I will try using some of your code to see it it makes a difference in output -- Meanwhile (back at the bug-eyed ranch), I'm going to retire for the evening but will be posting again tomorrow. Uggghhhhhh....
You're welcome Tate! \n is for creating a new line. Yes, it makes it easier on the eyes when reading the outputs. I don't know why you couldn't use \n when you are using switch coding syntax at this point but I'm not the one taking your class. You didn't mentioned if my programs works on your computer? Have a good evening!