88: Using switch statement Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following: // Percentage >= 90% : Grade A Percentage >= 80% : Grade B Percentage >= 70% : Grade C Percentage >= 60% : Grade D Percentage >= 40% : Grade E Percentage < 40% : Grade F
// Using switch statement Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer.
// Calculate percentage and grade according to following:
// Percentage >= 90% : Grade A
// Percentage >= 80% : Grade B
// Percentage >= 70% : Grade C
// Percentage >= 60% : Grade D
// Percentage >= 40% : Grade E
// Percentage < 40% : Grade F
#include <iostream>
using namespace std;
int main()
{
float phy_g, phy_t, chem_g, chem_t, bio_g, bio_t, math_g, math_t, comp_g, comp_t, per;
cout << "Enter your Physics marks: ";
cin >> phy_g;
cout << "Out of: ";
cin >> phy_t;
cout << "Enter your Chemistry marks: ";
cin >> chem_g;
cout << "Out of: ";
cin >> chem_t;
cout << "Enter your Biology marks: ";
cin >> bio_g;
cout << "Out of: ";
cin >> bio_t;
cout << "Enter your Math marks: ";
cin >> math_g;
cout << "Out of: ";
cin >> math_t;
cout << "Enter your Computer marks: ";
cin >> comp_g;
cout << "Out of: ";
cin >> comp_t;
per = (phy_g + chem_g + bio_g + math_g + comp_g) / (phy_t + chem_t + bio_t + math_t + comp_t) * 100;
switch (per >= 90)
{
case 1:
cout << "You got Grade A";
break;
case 0:
switch (per >= 80)
{
case 1:
cout << "You got Grade B";
break;
case 0:
switch (per >= 70)
{
case 1:
cout << "You got Grade C";
break;
case 0:
switch (per >= 60)
{
case 1:
cout << "You got Grade D";
break;
case 0:
switch (per >= 40)
{
case 1:
cout << "You got Grade E";
break;
case 0:
cout << "You got Grade F";
break;
}
break;
}
break;
}
break;
}
break;
default:
cout << "Invalid Input";
break;
}
return 0;
}
Comments
Post a Comment