Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that asks the user to input a grade that he or she received on a

ID: 3643857 • Letter: W

Question

Write a program that asks the user to input a grade that he or she received on an exam. The grade is an integer from 0-100 inclusive. The program should convert the numeric grade into the equivalent letter grade. Do the conversion by using a function Letter_Grade() that converts a numeric grade in the range 0-100; B if the grade is 80-89; C if the grade is 70-79; D if the grade is 65-69; and F if the grade is 64 or lower. After converting the grade, the program should display the numeric grade and the equivalent letter grade.

Explanation / Answer

#include <iostream>
using namespace std;

char calculate_grade( int percent ) {
    if ( percent >= 90 ) return 'A';
    if ( percent >= 80 ) return 'B';
    if ( percent >= 70 ) return 'C';
    if ( percent >= 65 ) return 'D';
    return 'F';
}

int main( int argc, char **argv ) {
    int percent;

    cout << "Enter your percentage grade (0-100) ";
    cin >> percent;

    if ( percent > 100 || percent < 0 ) {
        cerr << "Invalid grade." << endl;
    }

    cout << "Your grade is " ;
    cout.precision(2);
    cout << fixed << (float)percent;
    cout << "%. Your letter grade is " <<
            calculate_grade( percent ) << endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote