Practical Program Exercise 2 Percentage for 11th Computer Science
Switch statement
- The switch statement is a multi-way branch statement.
- It provides an easy way to dispatch execution to different parts of code based on the value of the expression.
- The switch statement replaces multiple if-else sequence.
CS2 – PERCENTAGE
QUESTION:
Write a C++ program to check percentage of a student and display the division (distinction, first, second, third or fail) scored using switch case
Percentage Division
>=80 Distinction
>=60 and <80 First division
>=50 and <60 Second Division
>=40 and <50 Third Division
<40 Fail
AIM:
To write a C++ program to check percentage of a student and display the division scored using switch case.
CODING:
#include<iostream>
using namespace std;
int main()
{
float percent;
int x;
cout<<“Enter your percentage:”;
cin>>percent;
cout<<“You Scored”<<percent<<“%”<<endl;
x=percent/10;
switch(x)
{
case 10:
case 9:
case 8:
cout<<“You have passed with Distinction”;
break;
case 7:
case 6:
cout<<“You have passed with First Division”;
break;
case 5:
cout<<“You have passed with Second Division”;
break;
case 4:
cout<<“You have passed with Third Division”;
break;
default:
cout<<“Sorry: You have failed”;
}
return 0;
}
OUTPUT 1:
Enter your percentage:79
You Scored 79%
You have passed with First Division
OUTPUT 2:
Enter your percentage:39
You Scored 39%
Sorry: You have failed
RESULT:
The Output was verified successfully