Answer to Question #323951 in C++ for Suren Raj

Question #323951

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





1
Expert's answer
2022-04-05T13:18:24-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS