Nov 22, 2014 at 6:46am UTC
The reason is the value that you input from the functiion is not returning back to main
Use reference or pointer parameter in getscore and determinegrade
Nov 22, 2014 at 7:08am UTC
Thank you very much, this problem has been solved... but another problem occurred...
my program keeps outputting
"Invalid response!"
"Please enter a valid response:
no matter what letter I enter, and the program won't go back to the beginning after calculate one grade at the first time
Nov 22, 2014 at 7:34am UTC
Try to use && instead of ||
Nov 22, 2014 at 7:52am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
#include<iostream>
#include<conio.h>
using namespace std;
void DisplayHeading()
{
cout << "Grade Calcuator" << endl;
}
//-----------------------------------------------
int GetScore()
{
int score;
cout << "Enter your score between 0 and 100 inclusive: " ;
cin >> score;
while (score > 100 || score < 0)
{
cout << "Invalid Score! " << endl;
cout << "Enter a score between 0 and 100 inclusive: " ;
cin >> score;
}
return score;
}
//-------------------------------------------------------
char DetermineGrade(int score)
{
char grade;
if (score >= 85)
grade = 'A' ;
else if (score >= 70)
grade = 'B' ;
else if (score >= 60)
grade = 'C' ;
else if (score >= 50)
grade = 'D' ;
else
grade = 'F' ;
return grade;
}
//---------------------------------------------
void DisplayGrade(int score, char grade)
{
cout << "The score is " << score << endl;
cout << "The Grade is " << grade << endl;
}
//------------------------------------------------
char GetResponse()
{
char response;
Beginning:
cout << "Do you want to calculate another grade? (Y/N) " ;
cin >> response;
if (response == 'y' || response == 'Y' || response == 'n' || response == 'N' )
return response;
else
{
cout << "Invalid response." << endl;
goto Beginning;
}
}
int main()
{
int Score = 0;
char Response = 0 , Grade = 0;
DisplayHeading();
do
{
Score = GetScore();
Grade = DetermineGrade(Score);
DisplayGrade(Score, Grade);
Response = GetResponse();
} while (Response == 'y' || Response == 'Y' );
_getch();
return 0;
}
Here try this.
Last edited on Nov 22, 2014 at 7:56am UTC
Nov 23, 2014 at 3:28am UTC
OMG!! Thank you very much! It works perfectly :D:D:D