Hi I manage to create some code to where it will read in a set of exam scores and display their category as well as if they enter an invalid number it repeats the code until the data is valid or until they enter the SENTINEL value but when I do it crashes after reading in 1 number and it does not repeat the loop if they enter in a invalid number.
const int SENTINEL = -999;
int getData(int score, string category);
string getCategory (int score, int amount, int & numOutstanding, int & numSatisfactory, int & numUnsatisfactory);
int main()
{
int score = 0;
int score2;
int amount = 0;
int numOutstanding = 0, numSatisfactory = 0, numUnsatisfactory = 0;
string category;
category = getCategory (score, amount, numOutstanding, numSatisfactory, numUnsatisfactory);
score2 = getData(score, category);
cout << score2 << endl;
return 0;
}
int getData(int score, string category)
{
do
{
cout << "Enter in exam scores from 0-100, -999 stops the program!" << endl;
cin >> score;
cout << "Your score is " << score << "Category: " << category << endl;
}
while(score < 0 || score > 100 && score < -999 || score > -999);
return 0;
}
string getCategory (int score, int amount, int & numOutstanding, int & numSatisfactory, int & numUnsatisfactory)
{
if(score >= 90 && score <= 100)
{
cout << "Outstanding!" << endl;
numOutstanding++;
}
else if(score >= 60 && score <= 89)
{
cout << "Satisfactory!" << endl;
numSatisfactory++;
}
else if(score >= 0 && score <= 59)
{
cout << "Unsatisfactory!" << endl;
numUnsatisfactory++;
}
amount++;
cout << "The number of Outstanding scores is: " << numOutstanding << "." << endl;
cout << "The number of Statisfactory scores is: " << numSatisfactory << "." << endl;
cout << "The number of Unsatisfactory scores is: " << numUnsatisfactory << "." << endl;
cout << "The total amount of scores entered is: " << amount << "." << endl;
return 0;
}