Need help with displaying my prints from my code

my code needs to check and print whether there are any A, B, C, or passing grades in the scores entered by the user. I've got mostly everything down except my code checks AND prints whether or not a score is A, B, C, or passing.

intended output:
Enter a score [-1 to quit]: 96
Enter a score [-1 to quit]: 94
Enter a score [-1 to quit]: 64
Enter a score [-1 to quit]: 92
Enter a score [-1 to quit]: 85
Enter a score [-1 to quit]: 88
Enter a score [-1 to quit]: 87
Enter a score [-1 to quit]: 86
Enter a score [-1 to quit]: -1
86 87 88 85 92 64 94 96
Minimum: 64
Maximum: 96
Average: 86.5
At least one 'A' grade entered
At least one 'B' grade entered
No 'C' grades entered
At least one passing grade entered

What I get:
Enter a score [-1 to quit]: 96
Enter a score [-1 to quit]: 94
Enter a score [-1 to quit]: 64
Enter a score [-1 to quit]: 92
Enter a score [-1 to quit]: 85
Enter a score [-1 to quit]: 88
Enter a score [-1 to quit]: 87
Enter a score [-1 to quit]: 86
Enter a score [-1 to quit]: -1
86 87 88 85 92 64 94 96
Minimum: 64
Maximum: 96
Average: 86.5
No 'A' Grades
At least one 'B' grade entered
No 'C' Grades
At least one passing grade entered
No 'A' Grades
At least one 'B' grade entered
No 'C' Grades
At least one passing grade entered
No 'A' Grades
At least one 'B' grade entered
No 'C' Grades
At least one passing grade entered
No 'A' Grades
At least one 'B' grade entered
No 'C' Grades
At least one passing grade entered
At least one 'A' grade entered
No 'B' Grades
No 'C' Grades
At least one passing grade entered
No 'A' Grades
No 'B' Grades
No 'C' Grades
No passing Grades
At least one 'A' grade entered
No 'B' Grades
No 'C' Grades
At least one passing grade entered
At least one 'A' grade entered
No 'B' Grades
No 'C' Grades
At least one passing grade entered

Here's my code:

#include <iomanip>
#include <iostream>
using namespace std;

struct Score
{
int value;
Score* next;
};


int main()
{



Score* head = 0;

int i = 0;
int nGreater = 0;
double average = 0.0;

int max = INT_MIN,
min = INT_MAX;

int grade[] = {0, 0, 0, 0, 0};






while (true)
{

Score* aScore = new Score;

cout << "Enter score [-1 to quit]: ";
cin >> aScore->value;
cin.ignore(1000,10);


if (aScore->value == -1) break;
if (aScore->value < min) min = aScore->value;
if (aScore->value > max) max = aScore->value;

aScore->next = head;
head = aScore;


}
cout << endl;



Score* aScore = new Score;

cout << "Scores entered:" << endl;
for (Score* p = head; p; p = p->next)
{
cout << p->value << ' ';
}
cout << endl;


cout << "Minimum = " << min << endl;
cout << "Maximum = " << max << endl;


int count = 0;
int sum = 0;
Score* p;
for (p = head; p; p = p->next)
{
sum += p->value;
count++;

}


if (count == 0)
{
cout << "No scores entered." << endl;
}
else
{
cout.setf(ios::fixed|ios::showpoint);
cout << setprecision(1);

float average = float(sum) / count;

cout << "The average of the " << count << " scores is " << average << endl;

}



for (p = head; p; p = p->next)
{
if (p->value >= 90 )
{
cout << "At least one 'A' grade entered"<<endl;

}
else
cout<< "No 'A' Grades"<< endl;



if (p->value >= 80 && p->value < 90)
{
cout << "At least one 'B' grade entered"<<endl;

}
else
cout<< "No 'B' Grades"<< endl;


if (p->value >= 70 && p->value < 80)
{
cout << "At least one 'C' grade entered"<<endl;

}
else
cout<< "No 'C' Grades"<< endl;



if (p->value >= 70 )
{
cout << "At least one passing grade entered"<<endl;

}
else
cout<< "No passing Grades"<< endl;
}


while (head)
{
Score* next = head->next;
delete head;
head = next;
}



return 0;
}

I'm mostly new to C++ and I really have no idea what I'm doing wrong in this code. Any help is greatly appreciated!
First of all, use the code tags (the <> button on the right side of the edit box). It allows other people to read the code and comment.

In your code, at some point you loop over all scores, and then for each score you print if it's an A, B, or C. What you need to do is to create a,b,c temporary variables outside that for loop, initialize them all by 0, and in your for loop just set a to 1 if you encounter a grade greater than 90, b=1 if the grade is between 80 and 90, and so on. Once the loop is finished, if a==1 you can print that there is at least an A grade. Same for b, and c. If (a==1) or (b==1) or (c==1) you have at least a passing grade.

There are a few other options. You can have the a,b,c variables to be booleans, and set them to false and true. Or keep them integers, and just increase the corresponding one when a score is given. This would allow you to say that you have 3 A, 1 B and no C
Topic archived. No new replies allowed.