Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is in C++ and it is a GPA calculator based on percentage. I am having trouble with the rounding, example: 74.6 should be 3.5

This is in C++ and it is a GPA calculator based on percentage. I am having trouble with the rounding, example: 74.6 should be 3.5 grade points and 74.4 should be 3.0 grade points. However both should up as 3.0, how can I 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions

Question

4. Identify cultural variations in communication style.

Answered: 1 week ago

Question

9. Understand the phenomenon of code switching and interlanguage.

Answered: 1 week ago

Question

8. Explain the difference between translation and interpretation.

Answered: 1 week ago