Question on my Program for intro to C calculating kilomters per liter.
Hey guys. I am new to C and I am having a hard time with my assignment. I am suppose to make a program that calculates kilometers per liter for 4 tanks of gasoline that a user fills in their car. this is what i have so far, i know its not right yet but i was just looking for some guidance. I am not sure if i am incrementing the number of tanks right and iam unsure how to get the average for the final calculations(i know its the total kilometers divided by the total liters). ANy help would be appreciated thank you in advance. Also i am using C-free-4.0 if that matters.
Code:
#include<stdio.h>
int main()
{
int i;
float res, km, lt, sum, avg;
sum=0;
avg= sum/4;
printf ("Welcometo the Johns kilometers per liter calculator.\n\n");
for(i=1;i<=4;i++)
{
printf ("Enter the number of Kilometers for tank %i: ",i);
scanf ("%d", &km);
printf ("Enter the number of liters used by tank %i: ",i);
scanf ("%f", <);
res = (float) km / lt;
printf ("the kiomleters per liter for tank %i is %.1f", i, res);
sum = sum + res;
}
printf ("Your overall average kilometers per liter for 4 tanks is %.1f", avg);
printf("Thanks for using the Johns KPL calculator program.");
getchar();
}