# Thread: AVG High/Low test scores

1. Originally Posted by BeldenML
Its funny I think Ive learned more working with you guys than from my professor!
That shouldn't surprise you...

Depending on the school you attend, most programming teachers are not programmers.
They are professional educators following a curriculum.

Some day when there's a minute or two at the end of class, ask your professor if you can see some of the software he or she has written...
That should be an interesting moment.

2. Originally Posted by BeldenML
I just added a sum-=num before the break so that way it adds whatever negative number the user enters to break the loop.
Someone gives you a bag of cookies and tells you that you can keep picking cookies one at a time out of the bag and eat them, stopping once you pick a cookie that is not a chocolate chip cookie (those cookies are poisoned). So what you do is pick a cookie. Oh, chocolate. You eat it. You pick another cookie. Walnut. You eat it. As you begin to froth at the mouth, you obtain and consume the antidote to the poison and then finally announce that you are done. Wouldn't it have been safer if you did not eat the walnut cookie to begin with?

Likewise, why add num to sum before you know that it is non-negative?

Originally Posted by BeldenML
My next step is just to print the high/low scores. Where should I start with that? laserlight will the code I have below work?
Generally, the idea is to keep track of the currently known highest/lowest scores. The interesting part is how you start with a highest/lowest score and then update it

As a side note: I discourage you from using a controlled infinite loop when you can make sensible use of the loop condition as in my suggestion.

3. Originally Posted by iceaway
I would suggest changing the contents of your while-loop a bit. First read the number, then check if it is below zero or not. If it is non-negative, add it to sum and increase the counter, if it is negative, exit the loop.

I would not use i as a float value here, since it it just a counter and it does not need floating point precision. Instead I would make your avg variable a float, and before printing the average, calculate the average into the avg variable and print that instead.

Code:
float avg;
...
avg = (float)sum/i;
He can also do it in the printf() as he is now...

Code:
printf("Average: %0.2f\n", ((float) sum) / i );

4. Originally Posted by CommonTater
He can also do it in the printf() as he is now...

Code:
printf("Average: %0.2f\n", ((float) sum) / i );
Indeed, I just figured he could make use of the avg variable defined previously :-) Somewhere along the line there usually comes a time when you need the avg again, then it's convenient to have it calculated already.

5. Great thanks iceaway! Any tips on where to start for printing high/low input grades?

6. Originally Posted by BeldenML
Great thanks iceaway! Any tips on where to start for printing high/low input grades?
As laserlight said you need to keep track of each new score, and check to see if it is a new "all time low" or "all time high". If the current score is lower than the previously recorded lowest score, you want to update it. The same goes for the highest score. Try putting some code together and post it here if you are running into problems

7. oh sry I didnt refresh the page and see all the new posts. Common I am going to ask him! lol

8. Hey guys the network at school I was logge dinto and saving my code on is down. Im not sure why but either way its 1am and I need to get at least a few hrs of sleep. I will be right back at it in the morning though so please check back if you get some time. Also I get what you guys are saying about the high/low score but Im not sure where to start. Do I add to the existing loop? Or start a new one? Anyways Im falling asleep so maybe Im just missing the obvious. Talk to ya guys in the morning! Thanks for the help!

9. Originally Posted by BeldenML
Also I get what you guys are saying about the high/low score but Im not sure where to start. Do I add to the existing loop? Or start a new one?
Because you are not saving the scores read, you must add to the existing loop.

10. ok Im back on it! laserlight let me TRY to add it into the loop and let me know if im on the right track..THANKS!

11. Tater what does the "Return 0" you added on line 21 do again?

12. Originally Posted by laserlight
Because you are not saving the scores read, you must add to the existing loop.
I thought I was saving the scores read as "int num"? laserlight Im kind of confused now..

13. Originally Posted by BeldenML
I thought I was saving the scores read as "int num"? laserlight Im kind of confused now..
That "saves" the current score.

Let me put it this way: I pick ten cards at random from a deck of cards. I show you the cards one by one. After showing you the tenth card, I ask you what is the highest number of the cards shown to you. The problem is, you have a bad memory, so you only remember that the number of the last card was 5. So, what is the highest number of the cards shown to you?

14. oh ok I see! Im not sure how to write that code though. should I set high=0 and low=0 and then add another if statement saying
Code:
if (num >= high)
{
num=high
}
Something like that?

15. Originally Posted by BeldenML
should I set high=0 and low=0 and then add another if statement saying
You're on a right track (there is another way, but stick to this one for now). However, suppose that the lowest score is 10. How would you ever update low to 10 when 0 is less than 10?