I have an assignment where I'm supposed to figure out grade information for multiple sections. I haven't even gotten through most of it, because I keep getting stuck on the score. For some reason I keep getting weird numbers when I enter the scores. The first number entered is supposed to be how many scores are in the section, and then followed by the scores. The only thing that is coming up correctly is the low score. The grade counts, and the highest score are getting really weird numbers. Can anyone tell me why this might be?
You need more indentation in your code to make it easier to read. Anyway, the problem is that highscore is not initialized before you use it for comparison. Also, you don't set sectionsum or any of the counters to zero before you start incrementing them.
And I apologize about the indentation. I will work on that in the future.
I just changed the following:
1 2
int highscore = 0;
int count;
But the only thing that changed in my output is that highscore is now showing the same thing as low score. For instance, when I type 2 80 90. I get the following output:
A's: 0
B's: 4196466
C's: 0
D's: 1810270640
F's: 32767
And then when I hit Ctrl D, the same output occurs (I would like this to stop happening, and only show the scores once.. also with the correct numbers).
And I get:
Lowest Score: 80
Highest Score: 80
Any other suggestions/hints as to why this occurring?
It seems like it is skipping all the else if statements, and going directly to the else of fCount++
Score of 50 is f judging from your code so first iteration is correct. About second: what is the value of count after first set of data is finished calculating? And what is it when second set is just began?
Actually there is no need for loop and count. Just add scoresInSection to *Count
Edit: Sligth rework of your program using C++ facilities:
The count is correctly displaying after the first set, but is showing a value of "80" after the second set.
For instance, an input of 3 90 80 70
is showing an output of
count: 3
count: 80
Isn't the loop necessary if I want to do multiple sections?
Also, how do I tell the program to stop incrementing the xCount of whatever the first value is? Should I do separate if statements, instead of the else if statements?
There are two passes here. On first one count starts from zero and increments until is is 3. On each iteration fCount is incremented. In the end fCount is incremented 3 - 0 = 3 times.
On second pass count starts from 3 (left from previous pass) and increments untill it will become 80. On each iteration bCount is incremented. In the end bCount is incremented 80 - 3 = 77 times.
So your program will report 77 A's and 3 F's after those two passes.
You can allso try to switch your two sets of variables around and see what happens.
Forgive me, but I'm still very confused. I'm a complete beginner.
What do you mean by changing the two sets of variables around? Why are there two passes?
I've been trying to study your code, but it is a little over my head, and not exactly what I'm trying to accomplish.
The first input has to be how many grades will be in that section, the scoresInSection variable. Then the input of that amount of grades before showing the letter grades.
I see now what my loop is doing in looping that amount of times on one letter grade, but still don't understand the second loop, or how to stop doing that without a while(cin) loop.