943,736 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3122
  • C++ RSS
Sep 19th, 2003
0

figure this out

Expand Post »
well this is what my program does:

//asks for input for number of gallons
enter the gallons of gas used (-1 to end):

//asks for input for number of miles
enter miles driven:

//then shows the miles / gallon for this tank
the miles / gallon for this tank was ...

it loops this untill the user presses -1
then i want it to find out the avg of all the miles/gallons.

problem is that avg is over written every time the loop starts
here is the code for the program.

#include <iostream.h>
#include <conio.h>

float gal;
float avg;
void gas();
//void totalavg();
void main()
{
while(gal>=0)
gas();
getch();
}

void gas()
{
float miles;

cout <<"enter the gallons of gas used (-1 to end): ";
cin >> gal;
if(gal!=-1)
{
cout <<"enter miles driven: ";
cin >> miles;
avg=miles/gal;
cout <<"the miles / gallon for this tank was "<<avg<<endl;
cout<<"\n";
}
}

i think i need avg to be a array.

anyhelp or hints to this problem would be greatly apprecaited.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
fakespike is offline Offline
58 posts
since Jul 2003
Oct 4th, 2003
0

Re: figure this out

Are you still working on this or did you figure it out?
Bob
Team Colleague
Reputation Points: 15
Solved Threads: 2
Junior Poster
Bob is offline Offline
129 posts
since Feb 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: help about programming
Next Thread in C++ Forum Timeline: stuck with definition





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC