菜鸟求救
我想编的程序是这样的:Enter the gallons used(-1 to end):12.8
Enter the miles driven:287
The miles/gallon for this tank was 22.421875
Enter the gallons used(-1 to end):10.3
Enter the miles driven:200
The miles /gallon for this tank was 19.417475
Enter the gallons used(-1 to end):5
Enter the miles driven :120
The miles/gallon for this tank was 24.000000
Enter the galons used (-1 to end ): -1
The overall average miles /gallon was 21.601423
我所编的程序如下:
#include<stdio.h>
main()
{
float gallons,miles,result,average,counter,total;
counter=0;
total=0;
while(gallons!=-1){
printf("\nEnter the gallons used(-1 to end):");
scanf("%f",&gallons);
printf("\nEnter the miles driven:");
scanf("%f",&miles);
result=miles/gallons;
counter=counter+1;
printf("The miles/gallon for this tank was%f\n",result);}
if(gallons=-1){
total=result+result;
average=(float)total/counter;
printf("\nThe overal average miles/gallon was%f",average);}
}
请问这里有什么错误,我非常渴望知道自己的错误,因为我还是菜鸟。