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.