#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
int nr = 0;
char ch = 0;
//This uses numbers
cout << "Type in number 1 or 2: ";
cin >> nr;
switch(nr)
{
case 1:
cout << "The number typed was 1!\n";
break;
case 2:
cout << "The number typed was 2!\n";
break;
default:
cout << "You didn't type in 1 or 2!\n";
break;
}
//This uses lowercase characters only
cout << "\n\n Type in character a or b: ";
cin >> ch;
switch(ch)
{
case 'a':
cout << "You typed in an A!\n";
break;
case 'b':
cout << "You typed in an B!\n";
break;
default:
cout << "You didn't type in a or b!\n";
break;
}
//This uses lowercase an uppercase characters
cout << "\n\nType in lowercase or uppercase a or b: ";
cin >> ch;
switch(ch)
{
case 'a': case 'A':
cout << "You typed in an A!\n";
break;
case 'b': case 'B':
cout << "You typed in an B!\n";
break;
default:
cout << "You didn't type in a or b!\n";
break;
}
getchar(); // wait for a key to be pressed.
return 0;
}
Download Visual C++ Source Code
I hope you found this c++ tutorial useful!
Don't forget to mention Apron Tutorials in your References!