This is how I need the output of the program to look:
Welcome to My Mileage calculator
This program will calculate the miles per gallon for you for three tanks of gas after you have entered the gallons used and the miles driven
Enter the number of gallons used for tank #1: 12.8
Enter the number of miles driven: 287.1
***The miles per gallon for this tank is 22.4
Enter the number of gallons used for tank #2: 10.3
Enter the number of miles driven: 200.2
***The miles per gallon for this tank is 19.4
Enter the number of gallons used for tank #3: 5.2
Enter the number of miles driven 120.9
***The miles per gallon for this tank is 23.3
Your overall average miles per gallon for three tanks is 21.5
Thank you for using My mileage calculator program
This is what I have written so far. My question is how do I get it to calculate overall average miles per gallon for the all three tanks and also how do I get it to ask for tank 1, tank 2 , tank 3? Mine just says tank 1 on each one.
Code:
#include <stdio.h>
void main (void)
{
/*Variable Delclarations*/
/*----------------------*/
int quotient, gallused, milesdriven;
float gallons_used;
float miles_driven;
float avg;
/*Display program info*/
/*--------------------*/
printf ("\nWelcome to Colleen's mileage calculator.\n");
printf ("\nThis program will calculate the miles per gallon for you for\n");
printf ("three tanks of gas after you have entered the gallons used and\n");
printf ("miles driven.\n");
/*Prompt user for information*/
/*------------------*/
for (gallused = 1; gallused <= 3; ++ gallused )
{
printf ("\nEnter the number of gallons used for tank #1: ");
scanf ("%f", &gallons_used);
fflush (stdin);
printf ("Enter the number of miles driven: ");
scanf ("%f", &miles_driven);
fflush (stdin);
gallons_used = miles_driven / gallons_used;
printf ("***The miles per gallon used for this tank is %.1f \n",gallons_used);
fflush (stdin);
} // end of loop
gallons_used = avg / gallons_used;
printf ("\nYour overall average miles per gallon for three tanks is %.1f \n", avg);
fflush (stdin);
/*Display Results*/
/*---------------*/
printf ("\nThanks for using Colleen's Mileage calculator program!\n");
} //end main