#include <iostream>
usingnamespace std;
int main()
{
double gpa = 0;
int exam = 0;
cout.setf (ios::fixed) ;
cout.setf (ios::showpoint) ;
cout.precision (1) ; // lines 14-16 fix decimal to 1 place
do {
cout << "Please enter your GPA (0.0 exits program) :" ; // ask for GPA
cin >> gpa ; // get user input for GPA
if (gpa == 0.0) {return 0;} // exits program if user enters 0.0 as GPA
if (gpa < 0.0 && gpa > 4.0) cout << "You've entered an invalid GPA or entrance score. " <<endl; // ask for user input again if not valid
elseif (gpa > 0.0 && gpa <= 4.0) {cout << "Thank you" << endl; }// check that user input is in required range for GPA
cout << "Please enter your entrance score :" ; // ask for entrance score
cin >> exam ; // get user input for entrance score
if (exam >=40 && exam <=44) cout << "Congratulations! You are hereby admitted to ABC Medical University";
elseif (exam <1 && exam >44) cout <<"You've entered an invalid GPA or entrance score. "; continue ; // ask for user input again if not valid
if (gpa >=3.7 && exam >=32) "Congratulations! You are hereby admitted to ABC Medical University"; //check for admission requirements
elseif (gpa <3.7 && exam <32) cout << "We are sorry! You are hereby denied admission to ABC Medical University.";
}
while (gpa != 0.0);
{
}
return 0;
}
I can get it to exit if I enter 0.0, but then it skips to asking for the entrance score without executing the other conditions. Any help would be greatly appreciated.
int main()
{
double gpa = 0;
int exam = 0;
cout.setf (ios::fixed) ;
cout.setf (ios::showpoint) ;
cout.precision (1) ;
do {
cout << "Please enter your GPA (0.0 exits program) :" ;
cin >> gpa ;
if (gpa == 0.0) {
return 0;
}
if (gpa < 0.0 && gpa > 4.0) // Check this: how can a number fit both conditions?
cout << "You've entered an invalid GPA or entrance score. " <<endl;
elseif (gpa > 0.0 && gpa <= 4.0) {
cout << "Thank you" << endl;
}
cout << "Please enter your entrance score :" ;
cin >> exam ;
if (exam >=40 && exam <=44)
cout << "Congratulations! You are hereby admitted to ABC Medical University";
elseif (exam <1 && exam >44) // Check this: how can a number fit both conditions?
cout <<"You've entered an invalid GPA or entrance score. ";
continue ; // This is sitting out on its own. Should it be part of else if above?
if (gpa >=3.7 && exam >=32)
cout << "Congratulations! You are hereby admitted to ABC Medical University"; //missing cout
elseif (gpa <3.7 && exam <32)
cout << "We are sorry! You are hereby denied admission to ABC Medical University.";
} while (gpa != 0.0);
return 0;
}
Thanks for pointing out my error on line 18. I guess it should be
if (gpa < 0.0 || gpa > 4.0)
on line 32 I wanted the
continue;
statement to go back to the beginning of the do while loop to ask for input again. Is that correct or is there a better way to accomplish this? Thanks for your help again.
With the continue sitting out on its own - it's going to run in all cases, so the code below it will be skipped.
There are different ways to approach this. You could use a short while loop to keep prompting the user for valid data on the gpa and exam. Then, with valid data, decide whether they're admitted.