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. :-)
#include<iostream>
usingnamespace std;
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;
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;
cout << "Press any other key to talk to an operator" << endl;
cin >> drChoice;
break;
case 2: cout << "Billing questions" << endl;
break;
case 3: cout << "Talking to a nurse" << endl;
break;
default: cout << "Talking to an operator" << endl;
}
switch (drChoice)
{
case 1: cout << "Making an appointment with Dr. Green..." << endl;
cin >> choice1;
break;
case 2: cout << "Making an appointment with Dr. Fox..." << endl;
cin >> choice2;
break;
case 3: cout << "Making an appointment with Dr. Davis..." << endl;
cin >> choice3;
break;
}
system ("pause");
return 0;
}
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.
I created your program today & made some changes to it. I moved lines 31 to 42 between lines 22 & 33. Put the default case back in the drChoice switch.
I don't know why you have the cin with Choice1, Choice2 & Choice3 now. I would remove them from the program as you don't need them.
The program should work now. It does for me unless I'm missing something. Good luck.
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!
After a good night's rest my eyeballs have retracted back into their sockets. I made a few changes in the program this morning, and it now works as it should. Yeah!!
I want to thank all the folks who took the time out of their busy schedules to assist. This forum is a godsend... Thank you so much!!