Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

# High Low Average Problem

Jem Edwards
Greenhorn
Posts: 22
I'm trying to have the program compute the high score, low score and average of all scores. It's doing the high & low ok but it's giving me only something close to an average. I can't even figure out how the average is being computed to the number it spits out. Any help is greatly appreciated!
[ edited to remove tabs and fix indention -ds ]
[ April 03, 2003: Message edited by: Dirk Schreckmann ]

Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
I'm not sure how SavitchIn works, but aren't you reading two entries in (the highlighted lines) and not adding the first score to either the total or the number of games played?
int min=max; //The max and min so far are the first score
int numberOfGames = 0; //number of bowling games
int total = 0; //sum of bowling game scores

William Barnes
Ranch Hand
Posts: 986
The easyest way of figuring out what your program is doing is to step though each line of code using a debugger. If you don't have a debugger put a lot of print statements. Each time you add another number to the total print it out.
"Adding number X to the running total of Y, the current count is Z."

Joel McNary
Bartender
Posts: 1840
You are omitting the first score from the average and the number of games. Test this by entering only one score. Given your code, you will get a high and low, but a Divide by Zero exception when it is calculating the average.