11. Program that inputs obtained marks of a student, calculates the percentage and displays grade.

Chapter 5: 

Conditional Structures

Programming Exercise

Problem # 11:

Write a program that inputs obtained marks of a student, calculates the percentage (assuming total marks are 1100) and displays grade according to the following rules:
    Percentage                                   Grade
    More than or equal to 80            A+
    Between 70 (inclusive) and 80    A
    Between 60 (inclusive) and 70    B
    Between 50 (inclusive) and 60    C
    Between 40 (inclusive) and 50    D
    Between 33 (inclusive) and 40    E
    Less than 33                                    F

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main ()
{
    int marks;
    float percentage;
    cout<<"Enter marks:";
    cin>>marks;
    percentage = (marks/1100.0)*100.0;
    if(marks>=0&&marks<=1100)
    {
      
        if(percentage>=80)
            cout<<"Grade is A+.";
        else if(percentage>=70)
            cout<<"Grade is A.";
        else if(percentage>=60)
            cout<<"Grade is B.";
        else if(percentage>=50)
            cout<<"Grade is C.";
        else if(percentage>=40)
            cout<<"Grade is E.";
        else
            cout<<"Grade is F.";
    }
    else
        cout<<"Invalid input.";
    return 0;
}


Let me know in the comment section if you have any question.

Previous Post:
10. Program that inputs temperature and displays a message.

Comments