私はこれを自分でデバッグする必要があることを知っています...しかし、私が試したことを信じてください。私は非常に恥ずかしいです。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;
}