Question: Write a function called driving _ cost ( ) with input parameters miles _ per _ gallon, dollars _ per _ gallon, and miles _
Write a function called drivingcost with input parameters milespergallon, dollarspergallon, and milesdriven, that returns the dollar
cost to drive those miles. All items are of type float. For example, when the function is called with the arguments it
returns to the calling program, which can be used or formatted by the program, appropriately.
Write a program called cardrivingcost which asks a user for the number of cars to process. It then, for each car, inputs the car's miles pe
gallon, the price of gas in dollars per gallon, and the number of driven miles all in float The program output the car's miles per gallon, the
price of gas in dollars per gallon, the number of driven miles, and the gas price of driving the car. The program calls the function
drivingcost to compute the gas price of driving the car.
Output each floatingpoint value with two digits after the decimal point, which can be achieved as follows:
printfyourvalue:
Example
Enter the number of cars:
for car
Enter miles per gallon:
Enter Dollar amount per gallon:
Enter the number of miles the car was driven:
Miles per gallon:
Dollars per gallon: $
Miles driven:
Driving cost: $
for car
Enter miles per gallon:
Enter Dollar amount per gallon:
Enter the number of miles the car was driven:
Miles per gallon:
Dollars per gallon: $
Miles driven:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
