In c++ You are a tired professor and need help determining the final grades at t
ID: 3883809 • Letter: I
Question
In c++ You are a tired professor and need help determining the final grades at the end of your C++ Programming course. You decide to write a program that converts a numerical grade into a letter grade and GPA. Specifications: You must use a switch statement to solve the problem. Prompt the user to enter a numerical grade (assume that it is an integer). Then use the following scales to determine the final letter grade and GPA: Print an error message if the grade is larger than 100 or less than 0 If you execute the program with the following underlined inputs, the output will be main.o Welcome to the Grade Calculation Program Enter Numerical Grade: -67 Error: Invalid Numerical Grade main.o Welcome to the Grade Calculation Program Enter Numerical Grade: 88 Letter Grade: B GPA: 3.0Explanation / Answer
Hi, here is the full executable code with comments,
#include <iostream>
using namespace std;
int main() {
int score;
cout<<"welcome to grade calculation program"<<endl;
cout<<"enter numerical grade"<<endl;
cin>>score;
if(score <= 100 && score>0 )
{
if(score==100)
{
cout<<"Letter Grade: A"<<endl;
cout<<"Grade: 4.0"<<endl;
return 0;
}
int x=score/10;
switch(x){
case 9:
cout<<"Letter Grade: A"<<endl;
cout<<"Grade: 4.0"<<endl;
break;
case 8:
cout<<"Letter Grade: B"<<endl;
cout<<"Grade: 3.0"<<endl;
break;
case 7:
cout<<"Letter Grade: C"<<endl;
cout<<"Grade: 2.0"<<endl;
break;
case 6:
cout<<"Letter Grade: D"<<endl;
cout<<"Grade: 1.0"<<endl;
break;
default:
cout<<"Letter Grade: F"<<endl;
cout<<"Grade: 0.0"<<endl;
break;
}
}
else
{
cout<<"Invalid numerical grade";
}
return 0;
}
Thumbs up if this was helpful, otherwise let me know in comments.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.