Re: [Dev-C++] Case statement - it SHOULD work...
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <Dan...@ao...> - 2002-04-07 12:51:32
|
In a message dated 4/7/2002 07:04:50 Central Daylight Time,
sp...@ho... writes:
Here's a quick bit of code. For some reason when I enter 1, 2, or 3 I get
the ERROR!!!!! message. If I change Choice to a char type and change 1 2 and
3 to a b and c it works.
What's wrong?
int main(int argc, char *argv[])
{
using namespace std;
int Choice; // Menu choice, as entered by user.
do
{
cout << "***** W E L C O M E *****\n";
cout << "\nChoose one of the following...\n";
cout << "1.Create Employee 2.Change wage 3.Exit\n";
cin >> Choice; // Get user's choice
switch (Choice) // Beginning our case flow control statements
{
case 'a' : cout << "Confirmed - Creating Employee...\n";
break;
case 'b' : cout << "Confirmed - Changing wage...\n";
break;
case 'c' : cout << "Exiting...\n";
break;
default : cout << "ERROR!!!!!!!!!!!!!!!!\n";
}
}while(Choice > '3' || Choice < '1');
You need to change your case statements
from case a' case'b' case 'c' to case '1' case '2' case '3' and the program
will respond according to the menu you've created.
With warmest regards,
Danny
|