-1

I am writing a program that calculates MPG at each fill up of a trip then when the user enters an empty string the loop quits and displays MPG of each fill up and total MPG of the full trip. I have created a algorithm which is shown below. Please give your input. Thanks.

Algorithm:

Do while tripmiles not equal to a blank line
    Get initial odometer miles from user and assign to tripA
    get final odometer miles from user and assign to tripB
    subtract tripB from tripA and assign the value to leg_1
    get gallons from user and assign the value to mygals
    divide leg_1 by mygals and assign value to leg_mpgs
    add each leg_mpgs and divide by total legs, assign to mytotalmpg 
Display each leg_mpg and mytotalmpg to screen

guys please keep in mind that i'm not writing code here. Its just an Algorithm. Thanks again

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179

1 Answers1

0

Have you considered what kind of data structure you are going to use for storing your odometer values? Using a list/array as a shift register would be simple to implement and would allow you to keep a running average of your total mpg.

Here is a link to using lists in python if you are unfamiliar.

Brandon Beggs
  • 70
  • 1
  • 8
  • what do I use if there is no set of stops. It is up to the user to put in the amount of stops they made. It could be 100 stops before the trips ends. so would lists/arrys still be a viable option? – user3015794 Feb 01 '14 at 05:52
  • or it could be only 5 stops – user3015794 Feb 01 '14 at 05:52
  • Python has "lists" they are dynamic arrays. Here is a nice example on using them without a fixed length. http://stackoverflow.com/questions/2910864/in-python-how-can-i-declare-a-dynamic-array – Brandon Beggs Feb 01 '14 at 16:38