Create a program that can calculate and compare the weekly fuel cost for two new cars. The calculation of the weekly fuel cost must be computed using a function. Functions enable us to break down a problem into smaller sections. By using a function to calculate the cost, this could be repeated multiple times or used in other programs without having to repeat the code and it should work reliably each time because it has been debugged and tested.   This program is intended to help a person to compare weekly fuel cost of two new cars. To calculate the weekly fuel cost for car you need several things: Weekly highway driving Weekly city driving Highway Miles per Gallon (MPG) City Miles per Gallon (MPG) The cost per gallon of gas. The steps to calculate the total weekly cost is: Calculate the amount of fuel used in highway driving: Take the number of highway miles driven and divide it by the highway mpg. Calculate the amount of fuel used in city driving: Take the number of city miles driven and divide it by the city mpg. Add the gallons used from each of the calculations to get the total gallons used. Take the gallons used and multiply that by the cost per gallon of gas.   The program should prompt the user for the following information at the beginning of the program (this same information is used for each car): Estimated weekly highway driving. Estimated weekly city driving. Estimated Cost for a gallon of gas.   It should prompt them for the following information for each car: The car make and model. Highway MPG for the car. City MPG for the car. Once the user has entered the required information, the program will pass all five pieces of information to a function and the function will calculate the weekly fuel cost and then return the information to the main program. This should happen for each car. Once each cost has been calculated, the program will then display the cost difference between the two cars to the user.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Create a program that can calculate and compare the weekly fuel cost for two new cars. The calculation of the weekly fuel cost must be computed using a function.

Functions enable us to break down a problem into smaller sections. By using a function to calculate the cost, this could be repeated multiple times or used in other programs without having to repeat the code and it should work reliably each time because it has been debugged and tested.

 

This program is intended to help a person to compare weekly fuel cost of two new cars.

To calculate the weekly fuel cost for car you need several things:

  • Weekly highway driving
  • Weekly city driving
  • Highway Miles per Gallon (MPG)
  • City Miles per Gallon (MPG)
  • The cost per gallon of gas.

The steps to calculate the total weekly cost is:

  • Calculate the amount of fuel used in highway driving:
    • Take the number of highway miles driven and divide it by the highway mpg.
  • Calculate the amount of fuel used in city driving:
    • Take the number of city miles driven and divide it by the city mpg.
  • Add the gallons used from each of the calculations to get the total gallons used.
  • Take the gallons used and multiply that by the cost per gallon of gas.

 

The program should prompt the user for the following information at the beginning of the program (this same information is used for each car):

  • Estimated weekly highway driving.
  • Estimated weekly city driving.
  • Estimated Cost for a gallon of gas.

 

It should prompt them for the following information for each car:

  • The car make and model.
  • Highway MPG for the car.
  • City MPG for the car.

Once the user has entered the required information, the program will pass all five pieces of information to a function and the function will calculate the weekly fuel cost and then return the information to the main program. This should happen for each car.

Once each cost has been calculated, the program will then display the cost difference between the two cars to the user.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 5 images

Blurred answer
Knowledge Booster
Types of Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education