Write a program to ask the user to input a value representing a score on a test. The value entered should be between 0 and 100. Use a IF control structure to output a message containing the letter grade corresponding to the score using the following table.
Score Letter grade
0-40 F
41-55 D
56-70 C
71-85 B
86-100 A
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main(void){
int score;
cout<<"Enter score between 0 and 100: ";
cin>>score;
//0-40 F
if(score>=0 && score<=40){
cout<<"Letter grade: F\n";
}
//41-55 D
else if(score>=41 && score<=55){
cout<<"Letter grade: D\n";
}
//56-70 C
else if(score>=56 && score<=70){
cout<<"Letter grade: C\n";
}
//71-85 B
else if(score>=71 && score<=85){
cout<<"Letter grade: B\n";
}
//86-100 A
else if(score>=86 && score<=100){
cout<<"Letter grade: A\n";
}else{
cout<<"Wrong score\n";
}
system("pause");
return 0;
}
Comments
Leave a comment