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;
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