i wrote this program, but somthenig is missing when i input -1 to finish. instead to have straight this :the overall average miles/gallons:.... my average consumption result, the program output this: Enter the miles driven and it follows:the overall average miles/gallons:
itwil be kind, i had two days stugling.
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int miles;
int gallons;
int counter;
int total;
float average;
float consumption;
counter = 0;
total = 0;
printf ("Enter the gallons used, -1 to end :");
scanf("%d", &gallons);
printf("Enter the miles driven :");
scanf("%d", &miles);
while (gallons != -1){
consumption = (float) miles / gallons;
printf("The miles / gallons for this thank was %.2f \n", consumption);
total += consumption;
counter += 1;
printf ("\nEnter the gallons used, -1 to end :");
scanf("%d", &gallons);
printf("Enter the miles driven :");
scanf("%d", &miles);
}
if (counter != 0){
average = (float) total / counter;
printf ("\nthe overall average miles/gallons %.2f \n", average);
}
else{
printf ("\nNo No No ");
}
system("PAUSE");
return 0;
}