This C++ Program which illustrates the use of switch statement. The program takes percentage as the input and the grade is output on the screen using the switch statement.
Here is source code of the C++ program which illustrates the use of switch statement. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to Illustrate Switch Statement
*/
#include <iostream>
using namespace std;
int main()
{
int percentage;
cout << "Enter the percentage : ";
cin >> percentage;
switch (percentage / 10)
{
case 10: case 9:
cout << "You have got grade A+" << endl;
break;
case 8:
cout << "You have got grade A" << endl;
break;
case 7:
cout << "You have got grade B+" << endl;
break;
case 6:
cout << "You have got grade B" << endl;
break;
case 5:
cout << "You have got grade C" << endl;
break;
default:
cout << "You have got grade D" << endl;
break;
}
}
$ g++ main.cpp $ ./a.out Enter the percentage : 98.5 You have got grade A+ $ ./a.out Enter the percentage : 68.71 You have got grade B
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Related Posts:
- Check Computer Science Books
- Apply for C++ Internship
- Apply for Computer Science Internship
- Apply for Information Technology Internship
- Practice Computer Science MCQs