Question #167661

Write a program that asks the user to input their percentage score.The program should then print out their grade. Use the ‘char’ data type to store the value of the grade.Use the following boundaries to assign the letter grade: Percentage >= 60% : Grade D Percentage >= 40% : Grade E Percentage < 40% : Grade F Percentage >= 90% : Grade A Percentage >= 80% : Grade B Percentage >=70% : Grade C 


Expert's answer

#include <iostream>

int main()
{
    int score;
    std::cout << "Please enter the percentage score: ";
    std::cin >> score;

    if(!std::cin || score < 0)
    {
        std::cout << "Bad input\n";
        return 1;
    }

    char grade;
    if(score >= 90) grade = 'A';
    else
    if(score >= 80) grade = 'B';
    else
    if(score >= 70) grade = 'C';
    else
    if(score >= 60) grade = 'D';
    else
    if(score >= 40) grade = 'E';
    else 
        grade = 'F';

    std::cout << "The grade is '" << grade << "'\n";
    
    return 0;    
}
LATEST TUTORIALS
APPROVED BY CLIENTS