C++
Write a program which accepts a numeric test score from the user. It will output the letter grade to the user corresponding to the score. Assume no “minus grades” (an A ranges from 90-100, B ranges from 80-89, C ranges from 70-79, D ranges from 60-69 and F is everything else.) Ensure that the score remains in the range of 0 to 100. As an example of the output:
Enter your numeric grade and I will tell you your output: 74 Your grade is a C.
#include <iostream> using namespace std; char getLetterGrade(double average){ char letter; if(average < 60) letter = 'F'; else if(average < 70) letter = 'D'; else if(average < 80) letter = 'C'; else if(average < 90) letter = 'B'; else letter = 'A'; return letter; } int main(){ double averageScore; cout<<"Enter your numeric grade and I will tell you your output: "; cin>>averageScore; cout<<"Your grade is a "<<getLetterGrade(averageScore)<<"."<<endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.