Answer to Question #167661 in C++ for sara

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 


1
Expert's answer
2021-03-01T02:04:22-0500
#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;    
}

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