14: The School has following rules for grading system: a. Below 25 - F, b. 25 to 45 - E, c. 46 to 50 - D, d. 51 to 60 - C, e. 61 to 80 - B, f. Above 80 - A. Ask user to enter marks and print the corresponding grade.
// The School has following rules for grading system:
// a. Below 25 - F
// b. 25 to 45 - E
// c. 46 to 50 - D
// d. 51 to 60 - C
// e. 61 to 80 - B
// f. Above 80 - A
// Ask user to enter marks and print the corresponding grade.
#include <iostream>
using namespace std;
int main(){
float total_marks, obtained_marks, percentage;
cout << "Enter obtained marks: ";
cin >> obtained_marks;
cout << "Enter total marks: ";
cin >> total_marks;
percentage = (obtained_marks / total_marks) * 100;
if(percentage < 25){
cout << "Your grade is: 'F'" << endl << "\nBetter luck next time\n";
}
else if(percentage >= 25 && percentage <= 45){
cout << "Your grade is: 'E'" << endl << "\nYou need to work harder\n";
}
else if(percentage > 45 && percentage <= 50){
cout << "Your grade is: 'D'" << endl << "\nYou need to work harder\n";
}
else if(percentage > 50 && percentage <= 60){
cout << "Your grade is: 'C'" << endl << "\nYou need to work harder\n";
}
else if(percentage > 60 && percentage <= 80){
cout << "Your grade is: 'B'" << endl << "\nNeed a bit more hard work\n";
}
else if(percentage > 80){
cout << "Your grade is: 'A'" << endl << "\nWell done. Keep it up\n";
}
return 0;
}
Input 1:
Enter obtained marks: 210
Enter total marks: 1100
Output 1:
Your grade is: 'F'
Better luck next time
Input 2:
Enter obtained marks: 350
Enter total marks: 1100
Enter obtained marks: 350
Enter total marks: 1100
Output 2:
Your grade is: 'E'
You need to work harder
Your grade is: 'E'
You need to work harder
Input 3:
Enter obtained marks: 550
Enter total marks: 1100
Output 3:
Your grade is: 'D'
You need to work harder
You need to work harder
Input 4:
Enter obtained marks: 600
Enter total marks: 1100
Output 4:
Your grade is: 'C'
You need to work harder
You need to work harder
Input 5:
Enter obtained marks: 800
Enter total marks: 1100
Output 5:
Your grade is: 'B'
Need a bit more hard work
Input 6:
Enter obtained marks: 990
Enter total marks: 1100
Output 6:
Your grade is: 'A'
Well done. Keep it up
Comments
Post a Comment