11. . Write a program using if-else statements that accepts a real number between 0 and 100 and, based on its value, reports its equivalent letter grade (A, B, C, D, or F). Add to your snapshots.
Write in c++
#include <iostream>
using namespace std;
int main() {
double n;
char grade;
cout<<"Enter a number between 0.0 and 100.0 :
";
cin>>n;
if(n <= 100.0 && n>80.0)
grade = 'A';
else if(n <= 80.0 && n>70.0)
grade = 'B';
else if(n <= 70.0 && n>60.0)
grade = 'C';
else if(n <= 60.0 && n>40.0)
grade = 'D';
else if(n <= 40.0)
grade = 'F';
cout<<"\nGrade = "<<grade;
return 0;
}
Output:
Enter a number between 0.0 and 100.0 : 67.8 Grade = C
Enter a number between 0.0 and 100.0 : 84.5 Grade = A
Enter a number between 0.0 and 100.0 : 33.6 Grade = F
Enter a number between 0.0 and 100.0 : 80.1 Grade = A
Do ask if any doubt.
Get Answers For Free
Most questions answered within 1 hours.