Can't figure out for the life of me what I am doing wrong.
I have been working on this one program for 3 weeks now and can't figure out for the life of me what I am doing wrong.
I can't calculate the overall average for (total miles divided by total gallons)
This is what my output is suppose to look like:
Welcome to my mileage calculator.
This program will calculate the miles per gallon for ou for three tanks of gas after you have entered the gallons used and 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 used for this tank is 22.4
Enter the number of gallons used for tank #1: 10.3
Enter the number of miles driven: 200.2
***The miles per gallon used for this tank is 19.4
Enter the number of gallons used for tank #1: 5.2
Enter the number of miles driven: 120.9
***The miles per gallon used for this tank is 23.3
Your overall average miles per gallon for three tanks is 21.5
Thanks for using my mileage calculator program!
This is what I have written so far! Please help me! What am I doing wrong? My overall average is coming up to 26.2?????
Code:
#include <stdio.h>
int main ()
{
/*Variable Declarations*/
/*----------------------*/
int quotient, gallused;
float gallons_used;
float miles_driven;
float total_miles;
float total_gal=0;
/*Display program info*/
/*--------------------*/
printf ("\nWelcome to my 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 #%d: ",gallused);
scanf ("%f", &gallons_used);
printf ("Enter the number of miles driven: ");
scanf ("%f", &miles_driven);
gallons_used = miles_driven / gallons_used;
printf ("***The miles per gallon used for this tank is %.1f \n",gallons_used);
total_gal = gallons_used + total_gal;
total_miles = total_miles + miles_driven;
} // end for loop
printf ("\nYour overall average miles per gallon for three tanks is %.1f \n",total_miles / gallons_used);
/*Display End Comment*/
/*---------------*/
printf ("\nThanks for using my mileage calculator program!\n");
} //end main