y using if-else statement write a C++ program to input marks of five subjects
Physics, Chemistry, Biology, Mathematics, and Computer. Calculate the percentage
and grade according to the following rules:
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() {
int phys, chem, bio, math, comp;
cout << "Enter marks on Physics: ";
cin >> phys;
cout << "Enter marks on Chemistry: ";
cin >> chem;
cout << "Enter marks on Biology: ";
cin >> bio;
cout << "Enter marks on Mathematics: ";
cin >> math;
cout << "Enter marks on Computer: ";
cin >> comp;
double avg = (phys + chem + bio + math + comp) / 5.0;
char grade;
if (avg >= 90) {
grade = 'A';
}
else if (avg >= 80) {
grade = 'B';
}
else if (avg >= 70) {
grade = 'C';
}
else if (avg >= 60) {
grade = 'D';
}
else if (avg >= 40) {
grade = 'E';
}
else {
grade = 'F';
}
cout << "The grade is " << grade << endl;
return 0;
}
Comments
Leave a comment