• Post Reply Bookmark Topic Watch Topic
  • New Topic

Code help  RSS feed

 
Adrian Martinez
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone,

Trying to make simple program for MPG calculation but I think the math part is wrong since the outputs don't make any sense.

Can any lead me to my mistake?

thank you





 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Adrian,

Welcome to CodeRanch!

Please, UseCodeTags (you can select the code and hit the 'Code' button while writing/editing the post).

Also, please TellTheDetails. That is, please let us know what is exact issue. What is expected output and what is actual output.

Typically, when you 'average the average', you don't get accurate results.

You may give a try to: (total miles driven)/(total gallons used).
 
Adrian Martinez
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is what I am trying to do.

I think my problem is the math portion.


 
Wayan Saryada
Ranch Hand
Posts: 119
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see that you have already wrote the code based on the instructions given to you. What do you think could wrong with the maths? Is it that your average is not exactly have a point 2 digits?
 
Adrian Martinez
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done the math multiple times and it seems wrong, i was assuming that my math is off.
 
Adrian Martinez
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok,

i figured it out, the formula was correct, it was the number inputted that were wrong.

so user error.
 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the formula is wrong, but if you have been told to use an incorrect formula you will have to use the incorrect formula.
 
Adrian Martinez
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain to me how the formula is wrong?
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adrian Martinez wrote:Can you explain to me how the formula is wrong?

I think it really depends on what you were asked to calculate.
At the moment you are working out 3 separate mpg values and then taking an average of those. This gives you 22.7586 mpg
If however, you just took the total mileage (1500) and divided it by the amount of gas used (66) you would get an average of 22.7272

As the example shows the first method, then what you are doing is right, but strictly speaking it is not the average mpg for the journey - it is the average of the average mpg for the three stages of the journey.
 
Adrian Martinez
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working with the mileage for 3 separate dates, as you can see the 2nd mileage of each date is subtracted by the 1st mileage and then divided by the 2nd gallons filled.

Ive never seen that type of formula before this assignment.

http://www.wikihow.com/Sample/Miles-Per-Gallon



 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuart A. Burkett wrote: . . . I think it really depends on what you were asked to calculate. . . .
They were asked to calculate the average of the average mpg for the three stages of the journey.

That is what they must calculate, even if it isn't a real value for anything.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!