im working on a switch statement and it wont work for me

Im tryn to get this switch statement to work, so that it will display a different message depending on the letter input. i get the program to run and it says "Enter A, B, or C" which is what i want, but once i enter A, B, or C, the program closes and does not display a message. here is my code. can anyone help me please?????

#include <iostream>
using namespace std;
int main()

{
char ch;

cout << "Enter A, B, or C: ";
cin >> ch;

switch(ch)

{
case 'a':
cout << "Hello";
break;
case 'b':
cout << "Goodbye";
break;
case 'c':
cout << "Have a nice day";

}

return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;
int main()

{
char ch;

cout << "Enter A, B, or C: ";
cin >> ch;
cin.ignore(); // this line 'ignores' a '\n', or a newline character, that gets left in the stream when you use cin

switch(ch) 

{
case 'a':
cout << "Hello";
break;
case 'b':
cout << "Goodbye";
break;
case 'c':
cout << "Have a nice day";

}

cin.get(); // this line is used to hold the console open until the user pressed the return key
return 0;
}


Are you using Dev-C++ by any chance?
Topic archived. No new replies allowed.