-
probably a simple answer
I know something is missing from this program, but I'm very new at this and can't figure it out. Could anyone help?
It should prompt the user to input 6 GPA's, but instead when you enter the first GPA it gives you the same answer six times.
Code:
include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
void instructions();
void displayGradeMsg();
//--------------------------------------
int main ()
{
// Instructions for the user.
instructions();
// Determines the message.
displayGradeMsg();
displayGradeMsg();
displayGradeMsg();
displayGradeMsg();
displayGradeMsg();
displayGradeMsg();
return 0;
}
//-------------------------------------
// Instructions.
void instructions()
{
cout << "This program prints an appropriate transcript "
<< "message for any grade-point" << endl;
cout << "average between 0.0 and 4.0. "
<< "Each time you are prompted to enter a GPA," << endl;
cout << "type a value between 0.0 and 4.0 "
<< "and then hit the <Enter> key." << endl << endl;
} // End instructions.
// Message determinants.
void displayGradeMsg()
{
int gpa1;
cout << "Please enter a grade-point average: ";
cin >> gpa1;
cout << endl;
if (gpa1 >= 3.5)
cout << "Highest honors for semester." << endl;
else if ((gpa1 >= 3.0) && (gpa1 < 3.5))
cout << "Dean's list for semester." << endl;
else if ((gpa1 >= 2.0) && (gpa1 < 3.0))
cout << endl;
else if ((gpa1 >= 1.0) && (gpa1 < 2.0))
cout << "On probation for next semester." << endl;
else ((gpa1 >= 0.0) && (gpa1 < 1.0));
cout << "Failed semester--registration suspended." << endl;
return;
} // End message determinants.
-
gpal is declared as an int, but you are using it as if it was a float. When you type in a float as input (like 3.7), then if gpal is an int it gets the 3 but not the .7. The next time through it sees the '.', and so it can't find an int. Maybe you should change the way gpal is declared.
Also, remember that the last part of an if - else if - else if - else statement doesn't have an expression after the else, so this:
Code:
else ((gpa1 >= 0.0) && (gpa1 < 1.0));
cout << "Failed semester--registration suspended." << endl;
should look like this:
Code:
else
cout << "Failed semester--registration suspended." << endl;
or this:
Code:
else if ((gpa1 >= 0.0) && (gpa1 < 1.0))
cout << "Failed semester--registration suspended." << endl;
-
Thanks!! I got it working.