aspose file tools
The moose likes Beginning Java and the fly likes High Low Average Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "High Low Average Problem" Watch "High Low Average Problem" New topic

High Low Average Problem

Jem Edwards

Joined: Mar 28, 2003
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

Joined: May 05, 2000
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 max=SavitchIn.readLineInt();
int min=max; //The max and min so far are the first score
int next = SavitchIn.readLineInt();
int numberOfGames = 0; //number of bowling games
int total = 0; //sum of bowling game scores

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
William Barnes
Ranch Hand

Joined: Mar 16, 2001
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."

Please ignore post, I have no idea what I am talking about.
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

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.
Try this instead:

This should calculate the numbers correctly.

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Jem Edwards

Joined: Mar 28, 2003
Posts: 22
Thanks all. Our internet class discussion group was figuring that there was something about the numbers the program was reading in but we couldn't figure it out.
Thanks a bunch!
I agree. Here's the link:
subject: High Low Average Problem