Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is in C++ and it is a GPA calculator based on percentage. It works but for some reason inputs such as 74.6 will not
This is in C++ and it is a GPA calculator based on percentage. It works but for some reason inputs such as 74.6 will not appear correctly, what could fix this?
#include
#include
#include
using namespace std;
double GradePoints(double *);
int main()
{
double percentage_grade = 0.0, grade_point;
cout << fixed << setprecision(1);
cout << "Enter percentage grades to convert to grade points. Enter '-1' to quit. ";
while(true)
{
cout << "Percentage grade: ";
cin >> percentage_grade;
if (percentage_grade == -1)
break;
while (cin.fail())
{
cout << "Invalid input. Please try again and enter a numeric value." << endl;;
cin.clear();
cin.ignore(INT_MAX, ' ');
cin >> percentage_grade;
}
try
{
grade_point = GradePoints(&percentage_grade);
cout << endl << percentage_grade << "% is " << grade_point << " grade points." << endl;
cout << endl;
}
catch (const char* msg)
{
cerr << endl << msg << endl;
cout << endl;
}
}
cout << " Good bye!" << endl << endl;
return 1;
}
double GradePoints(double *per)
{
if (*per < 0 || *per > 100)
{
throw "An problem occurred: Grade must be between 0.0 and 100.0. Please try again.";
}
if (*per >= 90)
return 5.0;
else if (*per >= 85 && *per <= 89)
return 4.5;
else if (*per >= 80 && *per <= 84)
return 4.0;
else if (*per >= 75 && *per <= 79)
return 3.5;
else if (*per >= 70 && *per <= 74)
return 3.0;
else if (*per >= 65 && *per <= 69)
return 2.5;
else if (*per >= 60 && *per <= 64)
return 2.0;
else if (*per >= 55 && *per <= 59)
return 1.5;
else if (*per >= 50 && *per <= 54)
return 1.0;
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started