I have this program but the function i created is not working properly, what am i doing wrong here?
#include<iostream>
#include<stdlib.h>
#include<cmath>
using namespace std;
void gpa(double, double);
int main()
{
const double INVALID_GRADE = -1.0;
bool needInput = true; // control for my input loop
double gpa;
double grade;
char ch='y';
while(needInput) // while the program needs valid input
{
while(ch == 'y' || ch == 'Y')
{
// Prompt for user input
cout << "Enter the grade to be converted ( 0 - 100 ) : " ;
cin >> gpa; // attempt to get the value from the user
if(cin.fail()) // if cin failed
{
cout << "\nInvalid Input! Please enter a numeric value. "; // error msg
fflush(stdin); // clears the keyboard buffer
cin.clear(); // reset the cin object
cout << "Do you want to continue ? y / n " << endl;
}
else if(gpa <= INVALID_GRADE)
{
cout << "\nGrade entered is invalid "; // error msg
fflush(stdin); // clears the keyboard buffer
cin.clear(); // reset the cin object
cout << "Do you want to continue ? y / n " << endl;
}
else
{
needInput = false; // program has valid input, cause the loop to end
// Processing
// calculate using funcion
gpa(gpa, grade);
// output
cout << "GPA is " << gpa << endl;
cout << "Do you want to continue ? y / n " << endl;
cin >> gpa;
}
}// end of input loop
} // end of while loop
cout << endl << endl;
system("pause");
return 0;
}
void gpa(double gpa, double grade)
{
if(grade >= 89.5 && grade < 100) then
gpa = 5.0;
elseif(grade >= 84.5 && grade < 88.5) then
gpa = 4.5;
else if(grade) >= 79.5 ) && grade < 83.5) then
gpa = 4.0;
else if(grade >= 74.5 && grade < 78.5) then
gpa = 3.5;
else if(grade >= 69.5 ) && grade < 73.5) then
gpa = 3.0;
else if(grade >= 64.5 ) && grade < 68.5) then
gpa 2.5;
else if(grade >= 59.5 && grade < 63.5){
gpa = 2.0;
else if(grade >= 54.5 && grade < 58.5) then
gpa = 1.5;
else if(grade >= 49.5 && grade < 53.5) then
gpa = 1.0;
else if(grade < 49.5) then
gpa = 0.0;
else
gpa = -1.0;
return gpa ; // return statement
}