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";
#include <iostream>
usingnamespace 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;
}