3.16 (Gas Mileage) 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:

Answers

Answer 1

Answer:

I am writing a C program.

#include <stdio.h> // for using input output functions

#include <stdbool.h> // for using a bool value as data type

int main() { // start of the main() function body

 int count=0; //count the number of entries

 double gallons, miles, MilesperGallon, combined_avg, sum; //declare variables

 while(true) {// takes input gallons and miles value from user and computes avg miles per gallon

      printf( "Enter the gallons used (-1 to stop): \n" ); //prompts user to enter value of gallons or enter -1 to stop

      scanf( "%lf", &gallons );//reads the value of gallons from user

   if ( gallons == -1 ) {// if user enters -1

     combined_avg = sum / count; //displays the combined average by dividing total of miles per drives to no of entries

     printf( "Combined miles per gallon for all tankfuls:  %lf\n", combined_avg ); //displays overall average value  

     break;} //ends the loop

     printf( "Enter the miles driven: \n" ); //if user does not enter -1 then prompts the user to enter value of miles

     scanf( "%lf", &miles ); //read the value of miles from user

MilesperGallon = miles / gallons; //compute the miles per gallon

printf( "The miles per gallon for tankful:  %lf\n", MilesperGallon ); //display the computed value of miles per gallon

  sum += MilesperGallon; //adds all the computed miles per gallons values

   count += 1;  } } //counts number of tankfuls (input entries)

Explanation:

The program takes as input the miles driven and gallons used for each tankful. These values are stored in miles and gallons variables. The program calculates and displays the miles per gallon MilesperGallon obtained for each tankful by dividing the miles driven with the gallons used. The while loop continues to execute until the user enters -1. After user enters -1, the program calculates and prints the combined miles per gallon obtained for all tankful. At the computation of MilesperGallon for each tankful, the value of MilesperGallon are added and stored in sum variable. The count variable works as a counter which is incremented to 1 after each entry. For example if user enters values for miles and gallons and the program displays MilesperGallon then at the end of this iteration the value of count is incremented to 1. This value of incremented for each tankful and then these values are added. The program's output is attached.

3.16 (Gas Mileage) Drivers Are Concerned With The Mileage Obtained By Their Automobiles. One Driver Has

Related Questions

What is a what if analysis in Excel example?

Answers

Answer:

What-If Analysis in Excel allows you to try out different values (scenarios) for formulas. The following example helps you master what-if analysis quickly and easily.

Assume you own a book store and have 100 books in storage. You sell a certain % for the highest price of $50 and a certain % for the lower price of $20.

(i really hope this is what u needed)

Other Questions
simplify the expression [tex]8p + 10 + - 2p - 1 + 10[/tex] A series circuit contains four resistors. In the circuit, R1 is 80 , R2 is 60 , R3 is 90 , and R4 is 100 . What is the total resistance? A. 330 B. 250 C. 460 D. 70.3 What is the maximum value of the function A client has made the decision to leave her alcoholic husband. She is feeling very depressed. Which nontherapeutic statement by the nurse conveys sympathy At a central train station, there are 4 different train routes with trains that leave every 6 minutes, 10 minutes, 12 minutes, and 15 minutes. If each train can hold up to 200 passengers, what is the maximum number of passengers who can leave the station on a train in one hour? In general, which step of the scientific method generally follows forming a hypothesis? A. Asking a question B. Making an observation C. Conducting an experiment D. Making a predictionNever mind, I already submitted my test, the answer is C. Related to the British rule in India..... What was the main motive of the British rule in India? How did they succeed in their objective? Carrie can inspect a case of watches in 5 hours.James can inspect the same case of watches in 3 hours.After working alone for 1 hour,Carrie stops for lunch.After taking a 40 minute lunch break,Carrie and James work together to inspect the remaining watches.How long do Carrie and James work together to complete the job? Will mark brainlist if it correct and well explained What does the denominator of the fraction \dfrac23 3 2 start fraction, 2, divided by, 3, end fraction mean? Help PLZ!!! Which statement accurately represents the arrangement of electrons in Bohrs atomic model? -Electrons move around the nucleus in fixed orbits of equal levels of energy. -Electrons move around the nucleus in fixed orbits of increasing levels of energy. -Electrons move randomly in the relatively large space surrounding the nucleus. -Electrons vibrate in fixed locations around the nucleus. Is anyone having issues viewing the answers to searched questions? Elliot became widowed after nearly 40 years of marriage. He has convinced himself that no one will ever love him again. His irrational thinking has caused him to suffer from depression, and he rarely leaves his house. What perspective might BEST explain his behavior sample of 64 observations is selected from a normal population. The sample mean is 215, and the population standard deviation is 15. Conduct the following test of hypothesis using the 0.025 significance level. H0: 220 H1: < 220 Is this a one- or two-tailed test? One-tailed test Two-tailed test The perimeter of a rectangle is 141 feet, and the length is twice the width. What are the dimensions ? Collectivist-inclined totalitarian states tend to enact laws that severely restrict private enterprises, while laws enacted by governments in democratic states, where individualism is the dominant political philosophy, tend to be pro-private enterprise and pro-consumer. This indicates that the The sum of ages Afful and Naomi is 34. In 5 years time , Afful will be 2 times the age on Naomi now. How old are they now. An electronics company designed a cardboard box for its new line of air purifiers. The figure shows the dimensions of the box.The amount of cardboard required to make one box is___square inches.a)130b)111c)109d)84 38. Convert 85 to a number in base eight.O 95 (base eight)O 105 (hase eight)O 115 (base eight)O 125 (base eight) Which of the following uses the correct punctuation?O A.I had sixty-seven dollars until-someone we're still not sure who stole my walletfrom my back pocket.OB.I had sixty-seven dollars until someone-we're still not sure who_stole my walletfrom my back pocket.O C.I had sixty-seven dollars until someone-we're still not sure who stole my walletfrom my back pocket.ODI had sixty-seven dollars untilsomeone we're still not sure who stole my walletfrom my back pocket.I need help! What is a what if analysis in Excel example?