the question says:
One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. Develop a program that will input the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls.
all i have is:
#include %26lt;stdio.h%26gt;
#include %26lt;iostream.h%26gt;
int main(void)
{
int miles, gallons, tankfull, mpg;
printf("enter miles traveled\n");
scanf("%d", %26amp;miles);
printf("enter # of gallons used\n ");
scanf("%d", %26amp;gallons);
mpg = miles/gallons;
printf("total miles per gallons: %d\n");
system("pause");
return 0;
}
i really don't know what i'm doing,,,
can u please explain what i need to do
thanks, thanks, thanks
I'm a beginer in c programming and i need help can someone help me! please?
again, float data type to the rescue:
int miles, gallons, tankfull;
float mpg;
...
...
...
mpg = (float)(miles/gallons); /* cast to float */
printf("total miles per gallons: %0.2f\n", mpg); /* note the difference in field modifiers for printf() */
Reply:You say for each tankful. So, not only do you need to know how many tankfuls there are, but also they must add up. So miles has to accumulate. Just like a rent a car. It writes down the mileage when you leave and return. You do the same, starting with 0 miles.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment