/**********************************************************/ //switch4.cpp //R. A. Hillyard //Last Modified 09/24/2001 // //This program demonstrates the use of the switch statement //where multiple cases result in the same action /*********************************************************/ #include<iostream> using namespace std; int main() { char choice; //holds user choice int pcount = 0; //count for how many passed int fcount = 0; //count for how many failed bool flag = true; //flag for loop do { //print menu of choices and get user choice cout << "\n\nPlease Enter one of the following grades based on the test score\n"; cout << "A\t For score >=90\n"; cout << "B\t For 80<= score <90 \n"; cout << "C\t For 70<= score <80 \n"; cout << "D\t For 60<= score <70 \n"; cout << "F\t For score <60 \n"; cout << "Q\t To Quit\n"; cin >> choice; //get user choice switch(choice) { case 'A': case 'B': case 'C': case 'D': case 'a': case 'b': case 'c': case 'd': cout << "passed\n"; pcount++; break; case 'F': case 'f': cout << "failed\n"; fcount++; break; case 'Q': case 'q': flag = false; break; default : cout << choice << " is not a valid entry - try again\n"; }//end switch }while(flag == true); cout << pcount << " passed, " << fcount << " failed\n"; return 0; }//end main /*********************Program Output************** Please Enter one of the following grades based on the test score A For score >=90 B For 80<= score <90 C For 70<= score <80 D For 60<= score <70 F For score <60 Q To Quit A passed Please Enter one of the following grades based on the test score A For score >=90 B For 80<= score <90 C For 70<= score <80 D For 60<= score <70 F For score <60 Q To Quit C passed Please Enter one of the following grades based on the test score A For score >=90 B For 80<= score <90 C For 70<= score <80 D For 60<= score <70 F For score <60 Q To Quit D passed Please Enter one of the following grades based on the test score A For score >=90 B For 80<= score <90 C For 70<= score <80 D For 60<= score <70 F For score <60 Q To Quit F failed Please Enter one of the following grades based on the test score A For score >=90 B For 80<= score <90 C For 70<= score <80 D For 60<= score <70 F For score <60 Q To Quit Q 3 passed, 1 failed
*/