In this example, you will learn to calculate grade of a student. The user will ask to enter marks obtained in 5 subjects and calculate obtained grade of that student using if…else statement.
Example: Program to Calculate Grade of Student
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#include <iostream> using namespace std; int main() { int mark[5], i; float sum=0,avg; cout<<"Enter marks obtained in 5 subjects :" << endl; for(i = 0; i < 5; i++) { cin >> mark[i]; sum = sum + mark[i]; } avg = sum / 5; cout << "Your Grade is "; if(avg > 80) { cout << "A"; } else if(avg > 60 && avg <= 80) { cout << "B"; } else if(avg > 40 && avg <= 60) { cout << "C"; } else { cout << "D"; } return 0; } |
1 2 3 4 5 6 7 |
Enter marks obtained in 5 subjects : 85 38 67 82 50 Your Grade is B |