This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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 ]
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
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.
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.
Joined: Mar 28, 2003
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!