Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,179 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,008 people online right now. Registration is fast and FREE... Join Now!




Do/While loop Help needed....

 
Reply to this topicStart new topic

Do/While loop Help needed....

stlsigma
6 Sep, 2007 - 06:28 PM
Post #1

New D.I.C Head
*

Joined: 21 Aug, 2007
Posts: 1


My Contributions
I'm trying to oompute miles driven and miles per gallon when the user inputs starting mileage, ending mileage, and gallons of gas used. I need to do this in a loop so they can enter info for up to 3 tanks. I can't get the miles driven to compute. I know the miles driven will equal the ending mileage minus the previous starting mileage but I can't get it to hold the new values in the loop.

Here's what I have so far:

do
{
cout << "Enter the gallons used (Enter -1 to End): ";
cin >> gallonsUsed;
totalGallonsUsed = (totalGallonsUsed + gallonsUsed);

cout << "Enter the ending mileage: ";
cin >> endingMileage;

milesDriven = (endingMileage - milesDriven);
cout << "Miles driven: " << milesDriven << endl;

totalMilesDriven = totalMilesDriven + milesDriven;

milesPerGallon = (milesDriven / gallonsUsed);
cout << "The miles/gallon for this tank was: " << milesPerGallon;

overallMilesPerGallon = (totalMilesDriven / totalGallonsUsed);

User is offlineProfile CardPM
+Quote Post

Xing
RE: Do/While Loop Help Needed....
6 Sep, 2007 - 06:33 PM
Post #2

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
Heard about arrays?
http://www.cprogramming.com/tutorial/lesson8.html
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 01:05AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month