Sure you can pass chars to a switch. I just made a sameple project confirming this. Heres the code:
#include
void main()
{
char letter = NULL;
cout << "Enter a letter." << endl;
cin >> letter;
switch(letter)
{
case ''a'': cout << "Hello" << endl; break;
case ''b'': cout << "Bye Bye" << endl; break;
default: cout << "I dont understand" << endl; break;
}
}
I think you can also pass strings and in the case part you would do this case "string": but i dont remember if i have ever done that or not.
-Snyper
[java] 2 questions
=============================Where's the 'any' key?=============================
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement