Original Post
I have to create a program that prompts the user for a grade, which is then sent to a function to be validated that it is in the correct grade range, and then converted to a gpa value. I get a lot of errors, if anyone could help me out it would be greatly appreciated. heres my code, which is now between source tags because Zahlman is a nice guy: Thank you!!! [Edited by - Zahlman on February 9, 2010 6:30:19 PM]
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
//Declarations
int grade; //Input variable
double gpa; //Output variable
int continue; //Used for while loop
//start of program output
cout << "Would you like to enter a grade? (yes or no): ";
cin >> continue;
//Start of loop
while (continue = "yes")
{
//Input
cout << "Please input a grade value: ";
cin >> grade;
//Processing
gpa = gpaConversion(grade);
//Output
cout << "Your GPA is: " << gpa << "\n";
}
system("pause");
return 0;
}
double gpaConversion()
{
/*GRADE EQUIVALENCY GUIDE
Grade Letter GPA Description
90 - 100 A+ 5.0 Outstanding
85 - 89 A 4.5 Outstanding
80 - 84 A- 4.0 Excellent
75 - 79 B+ 3.5 Very Good
70 - 74 B 3.0 Good
65 - 69 C+ 2.5 Pass
60 - 64 C 2.0 Pass
55 - 59 D 1.5 Conditional Pass
50 - 54 D- 1.0 Conditional Pass
Below 50 F 0.0 Fail*/
//Validate grade and convert to GPA
if (grade >= 89.5 && grade <= 100);
gpa = 5.0;
else if (grade >= 84.5);
gpa = 4.5;
else if (grade >= 79.5);
gpa = 4.0;
else if (grade >= 74.5);
gpa = 3.5;
else if (grade >= 69.5);
gpa = 3.0;
else if (grade >= 64.5);
gpa = 2.5;
else if (grade >= 59.5);
gpa = 2.0;
else if (grade >= 54.9);
gpa = 1.5;
else if (grade >= 49.5);
gpa = 1.0;
else if (grade >= 0);
gpa = 0.0;
else if (grade < 0 && grade > 100);
gpa = "unavailable due to an incorrect grade value. Please enter a grade between 0 and 100.";
return gpa;
}