Code:
#include<iostream>
#include<conio.h>
using std::cout;
using std::cin;
using std::endl;
int main()
{
double gallons=0,miles=0,average,tAverage,gSum=0,mSum=0;
do
{
cout<<"\n\nEnter the gallons used(-1 to end input):\t";
cin>>gallons;
cout<<"Enter the miles driven:\t\t\t\t";
cin>>miles;
average=miles/gallons;
cout<<"The miles/gallon for this tank was:\t\t"<<average;
gSum+=gallons;
mSum+=miles;
}
while(gallons!=-1);
cout<<"\nThe total gallons used are:\t\t\t"<<gSum;
cout<<"\nThe total miles driven are:\t\t\t"<<mSum;
tAverage=mSum/gSum;
cout<<"\nThe total average comes out:\t\t\t"<<tAverage;
getch();
}
-----------------------------------------------------end
if() needed?the gallons sum comes 1 less ,same is true for miles.whats wrong in this code?