Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Drivers are concerned with the mileage obtained by their automobiles. One driver

ID: 3787083 • Letter: D

Question

Drivers are concerned with the mileage obtained by their automobiles. 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. Here is a sample input/output dialog: Enter the gallons used (-1 to end) 12.8 Enter the miles driven: 287 The miles/gallon for this tank was 22.421875 Enter the gallons used (-1 to end): 10.3 Enter the miles driven: 200 The miles/gallon for this tank was 19.417475 Enter the gallons used (-1 to end): 5 Enter the miles driven: 120 The miles/gallon for this tank was 24.00000 Enter the gallons used (-1 to end): -1 The overall average miles/gallon was 21.601423 A palindrome is a number or a text phrase that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome 12321, 55555, 45554 and 11611. Write a program that reads in a five-digit integer and determines whether or not it's a palindrome.

Explanation / Answer

1. C program to calculate average milage from gallons and miles:

#include<stdio.h>
int main()
{
float gallons = 0, totgallons = 0, miles = 0, totmiles = 0;
   do {
      printf("Enter the gallons used(-1 to end): ");
      scanf("%f",&gallons); // Read the gallons from user
      if (gallons > 0)       // Check if entered value is valid
      {
   printf("Enter the miles driven: ");
   scanf("%f",&miles); //Read miles from user
   printf("The miles/gallon for this tank was %f ", miles/gallons);
   totgallons = totgallons + gallons;   //calculate total gallons
   totmiles = totmiles + miles;         //calculate total miles
       }
   } while (gallons != -1);
   if (totgallons > 0) {
      // print the final average
      printf("The overall average miles/gallons was %f", totmiles/totgallons);
   }
   else
   {
      printf(" No data to calculate average");
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote