Thread: help please!
View Single Post
Old Mar 18th, 2005, 12:26 AM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Ok, well, you only really need four numbers. I would use float or double as gallons and total gallon instead of ints, so to be more precise. Have num1 and num2, just as you have. Then have totalGallons, which will hold the sum of all the inputs so far, and then have a totalMiles variable.

Your while loop should be

while(num1>-1)
instead of num1>=-1 because that would include -1, and the loop wouldn't end when you inputted -1.

Inside the while loop, first of all, add num1 to totalGallons. Ask for num2. Add num2 to total miles.

There's no need for that second loop.

Simply print out miles per gallon by totalGallons/totalMiles. Use a float to be more precise.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote