0

Hey everyone. I am supposed to create a program that will input the miles driven and gallons used for each tank full of gas. program has to calculate and display the miler per gallon obtained for each tankful and print the combined miles per gallon for all tank fulls up to that point.

I am trying to figure out how i would actually go about doing this. i have a rough idea but i know this is not going to work. i have been trying to figure it out for ever, anybody care to point me in the right direction? here is my pseudocode so far...

Initialize mpg to 0
initialize tank to 1
Int miles
Int gallons


While not sentinel value
Prompt the user to enter the miles driven
Prompt user to enter total gallons used

Miles++
Gallons++

Mpg=miles/gallons
Mpg++

Print the total mpg

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Mikeyp926
0

That code looks like you are on the right track, however, I'm not so sure about the "Miles++ and Gallons++" part. Instead of incrementing them, don't you want to add the values input to those variables? Also, you might want to create some separate variables to keep track of the total miles driven and total gallons used. Then at the end of the program you will be able to calculate the total mpg.

Hope that helps!
-Michael

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.