figure this out

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2003
Posts: 58
Reputation: fakespike is an unknown quantity at this point 
Solved Threads: 0
fakespike fakespike is offline Offline
Junior Poster in Training

figure this out

 
0
  #1
Sep 19th, 2003
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 129
Reputation: Bob is an unknown quantity at this point 
Solved Threads: 1
Team Colleague
Bob Bob is offline Offline
Team Member

Re: figure this out

 
0
  #2
Oct 4th, 2003
Are you still working on this or did you figure it out?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC