// Mr. Minich
// CMPSC 101
// Ch. 7 Demo Program #5
// January 30, 2000
// Purpose - to illustrate the use of the switch structure
#include <iostream>
using namespace std;
int main()
{
int num1 = 0; // used in a switch structure example
switch (num1)
{
case 0:
cout << "0" << endl;
break;
case 1:
cout << "1" << endl;
break;
case 2:
cout << "2" << endl;
break;
default:
cout << "none of the above" << endl;
break;
}
num1 = 5;
switch (num1)
{
case 0:
cout << "0" << endl;
break;
case 5:
cout << "5" << endl; // forgot the break statement
default:
cout << "None of the above" << endl;
break;
}
// "None of the above" is displayed in addition to "5" because of the missing break statement.
switch (num1)
{
case 1:
case 2:
case 3:
case 4:
case 5:
cout << "you failed the 10 point quiz" << endl;
break;
case 6:
cout << "you scored a D on the quiz" << endl;
break;
case 7:
cout << "you scored a C on the quiz" << endl;
break;
case 8:
cout << "you earned a B on the quiz" << endl;
break;
case 9:
case 10:
cout << "you earned an A on the quiz. Well done!" << endl;
break;
}
// several values can be joined in one area of a switch as in the
// example above where values 1 through 5 and values 9 and 10 both
// share the same cout statements
return 0;
}// end of main