score exams and categories

I am having issues getting the outstanding, satisfactory, and unsatisfactory to count and print correctly. For all 3 it displays the number 2. I have no idea what else to try.

a. Write a program to read in a collection of exam scores ranging in value from 0 to 100. Your program should display the category of each score. It should also count and display the number of outstanding scores (90 to 100), the number of satisfactory scores (60 to 89), and the number of unsatisfactory scores(0 to 59).

b. Modify your program so it also displays the average score at the end of the run.


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
#include <iostream>
#include <iomanip>
using namespace std;

void displayGrade(int);
void outstanding (int);
void satisfactory (int);
void unsatisfactory (int);

int main()
{
   const int SENTINEL = -99;    
   int score, sum = 0, count = 0, outstanding = 0, satisfactory = 0, unsatisfactory =0;        							
   double average;				
cout <<"Assignment 16 by " << endl << endl;
   cout << "Enter scores one at a time as requested." << endl;
   cout << "When done, enter " << SENTINEL << " to finish entering scores." << endl;
   cout << "Enter the first score: ";
   cin >> score;
   while (score != SENTINEL)
   {
      sum += score;
      count++;
      displayGrade(score); 
      cout << endl<< "Enter the next score: ";
      cin >> score;
	  if (score >= 90)
 { 
	 outstanding = score >= 90;
	outstanding++;	  
}
else if (score >=60){
satisfactory = score >= 60;
satisfactory++;
}
else {
unsatisfactory =score <=59;
unsatisfactory++;
}
   } 

   cout << endl << endl; 
   cout << "Number of scores processed is " << count << endl;
   cout << "Sum of exam scores is " << sum << endl;
   	cout << "The number of Outstanding scores is: " << outstanding << endl;
	cout << "The number of Satisfactory scores is: " << satisfactory << endl;
	cout << "The number of Unsatisfactory scores is: " << unsatisfactory << endl;
   if (count > 0)
   {
      average = sum / count;
      cout << "Average score is " << average << endl;
   }

   return 0;
}   

void displayGrade(int score)
{
   if (score >= 90)
	   cout << "Grade is A" << endl;
   else if (score >= 80)
	   cout << "Grade is B" << endl;
   else if (score >= 70)
	   cout << "Grade is C" << endl;
   else if (score >= 60)
	   cout << "Grade is D" << endl;
   else
	   cout << "Grade is F" << endl;
}
Last edited on
Line 29, 33 and 37 looks suspicious.
Last edited on
1) Your first score will not register any category.. First check for category, then take the input of next score at the very end of the while loop...
2) Keep a check for scores to be less than 100, else the user can enter meaningless values...
3) Yeah, Lines 29, 33 and 37 don't make much sense... Get rid of them...
4) Lines 6, 7, 8 declare functions which you never use or define...? Why declare them?
I'm still lost. If I take out lines 29, 33, 37 how will i get the calculations for the right category? I thought about adding a check for "invalid input" if a value was over 100 but it was not in the assignment so i did not get there yet. I did take out 6,7,8. I had them in there for a different way i tried and forgot to take them out. This is frustrating. Dang online classes and instructors hardly available.
What exactly did you mean to achieve by lines 29, 33 and 37? The statements as such don't make sense and are probably messing up your count... You've already made a check for the score to be in a certain range with the if loops, and then you increment the corresponding variable... And the 100 check may not be in the assignment, but its always a good habit... And it won't harm your program in any way, so why not...
I got it thanks for the tips. I took those lines out and moved the rest of the if statements inside the while loop.
Topic archived. No new replies allowed.