我知道我应该自己调试这个......但相信我,我已经尝试过了,我很尴尬。我不明白为什么我的 while 循环是无限循环的。任何人都可以帮忙吗?
#include <stdio.h>
int main ( void )
{
double milesDriven;
double gallonsUsed;
double totalMilesDriven;
double totalGallonsUsed;
float milesPerGallon;
float totalMpG;
printf( "%s", " Enter the gallons used (-1 to end): " );
scanf( "%i", &gallonsUsed);
printf( " Enter the miles driven: " );
scanf( "%i", &milesDriven);
while ( gallonsUsed != -1 || milesDriven != -1)
{
totalGallonsUsed += gallonsUsed;
totalMilesDriven += milesDriven;
milesPerGallon = ( milesDriven / gallonsUsed );
printf( " The miles/gallon for this tank was %f\n", milesPerGallon );
printf( "%s", " Enter the gallons used (-1 to end): " );
scanf( "%i", &gallonsUsed);
printf( " Enter the miles driven: " );
scanf( "%i", &milesDriven);
}
totalMpG = ( totalMilesDriven / totalGallonsUsed );
printf( " The overall average miles/gallon was %.6f\n ", totalMpG);
return 0;
}