Question

Write a function DrivingCost with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar cost to drive those miles. All items are of type double. If the function is called with 5020.03 .1599, the function returns 7.89975 .

Define that function in a program whose inputs are the car's miles/gallon and the gas dollars/gallon (both doubles). Output the gas cost for 10 miles, 50 miles, and 400 miles, by calling your DrivingCost function three times.

Output each floating-point value with two digits after the decimal point, which can be achieved as follows: printf("%0.2lf", yourValue);

Ex: If the input is:

20.0 3 .1599

the output is:

1.58 7.90 63.20

Your program must define and call a function:

double Drivingcost(double drivenMiles, double milesPerGallon, double dollarsPerGallon)

Note: This is a lab from a previous chapter that now requires the use of a function.

Write a function Driving Cost with input parameters driven Miles, milesPerGallon, and dollarsPerGallon, that returns the doll


1 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

C++ code for computing driving cost

#include
using namespace std;
double DrivingCost(double drivenMiles, double milesPerGallon, double dollarsPerGallon)
{
return (drivenMiles/milesPerGallon)*dollarsPerGallon;
}
int main()
{
double milespg=20.0;
double dollarsGallon=3.1599;
  
cout<<" driving cost for 10 miles "< cout<<" driving cost for 50 miles "< cout<<" driving cost for 400 miles "<   
return 0;
}

Add a comment
Answer #2

Coral


Function DrivingCost(float drivenMilesIn, float milesPerGallon, float dollarsPerGallon) returns float cost

      

   cost = (drivenMilesIn / milesPerGallon) * dollarsPerGallon

      

   

Function Main() returns nothing

   float milesPerGallon

   float dollarsPerGallon

   float array(3) drivenMiles

   float drivenMilesIn

   integer i

   

   milesPerGallon = Get next input

   dollarsPerGallon = Get next input

   

   drivenMiles[0] = 10

   drivenMiles[1] = 50

   drivenMiles[2] = 400

   

   for i = 0; i < drivenMiles.size; i = i + 1

      drivenMilesIn = drivenMiles[i]

      if i == drivenMiles.size - 1

         Put DrivingCost(drivenMilesIn, milesPerGallon, dollarsPerGallon) to output with 2 decimal places

         

      else

         Put DrivingCost(drivenMilesIn, milesPerGallon, dollarsPerGallon) to output with 2 decimal places

         Put " " to output


answered by: Jason Keim
Add a comment
Know the answer?
Add Answer to:
Write a function DrivingCost with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a method drivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallo

    6.26 LAB: Driving cost - methodsWrite a method drivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar cost to drive those miles. All items are of type double. If the method is called with 50 20.0 3.1599, the method returns 7.89975.Define that method in a program whose inputs are the car's miles/gallon and the gas dollars/gallon (both doubles). Output the gas cost for 10 miles, 50 miles, and 400 miles, by calling your drivingCost() method three times.Output...

  • Driving cost - methods

    3.14 LAB: Driving cost - methodsWrite a method drivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar cost to drive those miles. All items are of type double. If the method is called with 50 20.0 3.1599, the method returns 7.89975.Define that method in a program whose inputs are the car's miles/gallon and the gas dollars/gallon (both doubles). Output the gas cost for 10 miles, 50 miles, and 400 miles, by calling your drivingCost() method three times.Output each...

  • Python 3 please. 6.27 (Functions) HW: Driving cost - functions Write a function DrivingCost with input...

    Python 3 please. 6.27 (Functions) HW: Driving cost - functions Write a function DrivingCost with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar cost to drive those miles. Ex: If the function is called with 50 20.0 3.1599, the function returns 7.89975. Define that function in a program whose inputs are the car's miles/gallon and the gas dollars/gallon (both floats). Output the gas cost for 10 miles, 50 miles, and 400 miles, by calling your DrivingCost function three...

  • PLEASE WRITE IN C++ 2.25 LAB: Driving costs Driving is expensive. Write a program with a...

    PLEASE WRITE IN C++ 2.25 LAB: Driving costs Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) as input, and output the gas cost for 10 miles, 50 miles, and 400 miles. Output each floating-point value with two digits after the decimal point, which can be achieved by executing cout << fixed << setprecision(2); once before all other cout statements. Ex: If the input is: 20.0 3.1599 the output is: 1.58 7.90 63.20 Note:...

  • A pedometer treats walking 2,000 steps as walking 1 mile. Write a program whose input is...

    A pedometer treats walking 2,000 steps as walking 1 mile. Write a program whose input is the number of steps, and whose output is the miles walked. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print('{:.2f}'.format(your_value)) Ex: If the input is: 5345 the output is: 2.67 Your program must define and call the following function. The function should return the amount of miles walked. def steps_to_miles(user_steps) answer must be in Phython...

  • A jiffy

    3.13 LAB: A jiffyA “jiffy” is the scientific name for 1/100th of a second. Given an input number of seconds, output the number of "jiffies."Output each floating-point value with two digits after the decimal point, which can be achieved as follows:System.out.printf("%.2f", yourValue);Ex: If the input is:15the output is:1500.00Your program must define and call a method:public static double secondsToJiffies(double userSeconds)

  • (JAVA) One lap around a standard high-school running track is exactly 0.25 miles

    (JAVA) 7.12 LAB: Miles to track lapsOne lap around a standard high-school running track is exactly 0.25 miles. Write a program that takes a number of miles as input, and outputs the number of laps.Output each floating-point value with two digits after the decimal point, which can be achieved as follows: System.out.print f("%.2 f", yourValue);Ex: if the input is.1.5the output is:6.00Ex: if the input is:2.2the output is:8.80

  • (C++) One lap around a standard high-school running track is exactly 0.25 miles

    17.1 LAB: Niles to track laps  (C++)One lap around a standard high-school running track is exactly 0.25 miles. Write a program that takes a number of miles as input, and outputs the number of laps.Output each floating-point value with two digits after the decimal point, which can be achieved by executing cout << fixed << setprecision(2); once before all other cout statements.Ex. If the input is:1.5the output is:6.00Ex: If the input is:2.2the output is:8.80Your program must define and call a function: double...

  • Drivers are concerned with the mileage their automobiles get. One driver has kept track of several...

    Drivers are concerned with the mileage their automobiles get. One driver has kept track of several tankfuls of gasoline by recording the miles driven and gallons used for each tankful. Develop a C# app that will input the miles driven and gallons used (both as integers) for each tankful. The app should calculate and display the miles per gallon obtained for each tankful and display the combined miles per gallon obtained for all tankfuls up to this point. All averaging...

  • LOGIC TUI Computer Program CHALLENGE ACTIVITY 2.9.2: Code basics See Coral: Code basics for solution help....

    LOGIC TUI Computer Program CHALLENGE ACTIVITY 2.9.2: Code basics See Coral: Code basics for solution help. Jump to level 1 Write code that outputs: A3 G7 TOUS: Home 3.6. Variables/Assignments: Driving costs My library > PRG 211: Algorithms & Logic for Computer Programming home > 6: Variables/Assignments: Driving costs zyBooks catalog He Start Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 10 miles, 50 miles,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT