Write a program that asks the user to enter the number of miles traveled and the
ID: 3542091 • Letter: W
Question
Write a program that asks the user to enter the number of miles traveled and the number of gallons of gasoline consumed. It should then calculate and display the miles-per-gallon value. Confine your output to 1 decimal place.
Next, using the fact that one gallon is about 3.785 liters and one mile is about 1.609 kilometers, it should convert the mile-per-gallon value to a liters-per-100-km value, the usual European way of expressing fuel consumption, and display the result, showing 2 decimal places. Use symbolic constants (using const or #define) for the two conversion factors in your program.
Explanation / Answer
#define LITRE 3.785
#define KM 1.609
int main()
{
int miles, gallons;
printf("Enter the number of miles travelled ");
scanf("%d ",&miles);
printf("Enter the gallons of gasoline consumed");
scanf("%d ",%gallons);
double milespergallon = (double) (miles/ gallons);
printf("The miles per gallon is %.0lf ",milespergallon);
//to convert
double miles2 = miles * KM;
double gallons2 = gallons * LITRE;
milespergallon = miles2/gallons2;
printf("The miles per gallon in European standardn is %.00lf ",milespergallon);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.