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

Function Name: roadTrip % Inputs (4): - (double) the number of miles a car can t

ID: 3648103 • Letter: F

Question

Function Name: roadTrip
% Inputs (4): - (double) the number of miles a car can travel with the
% amount of gas given in the second input
% - (double) the gallons of gas required to drive the number
% of miles in the first input
% - (double) the length (in miles) of a road trip
% - (double) the price of gas per gallon
% Outputs (1): - (double) the cost of the amount of gas needed for the road
% trip
%
% Function Description:
% Write a function named "roadTrip" that takes in the number of miles a
% car can travel with a specified number of gallons of gas, as well as
% the length of a road trip and the price of gas per gallon. The function
% outputs the cost of the amount of gas needed for the trip. The price
% should be rounded up to the nearest hundredth.
%
% Notes:
% - Do not round any values in the intermediate steps.
%
% Hints:
% - You may find the ceil() function useful.
%
% Test Cases:
% cost1 = roadTrip(155.36, 5.12, 350, 3.84)
% cost1 => 44.3000
%
% cost2 = roadTrip(208, 8, 1009, 3.69)
% cost2 => 143.2100
%

Explanation / Answer

%I'm not sure how you got your test answers with no intermediate rounding %with no rounding, with a calculator, I got: % cost1=44.292481977342945417095777548919 = 44.290 =/= 44.3000 % cost2=143.20038461538461538461538461538= 143.200 =/= 143.2100 function cost = roadTrip(mlimit, grequired, miles, price ) cost=round(price*miles*(grequired/mlimit)*100)/100; % rounding to hundredths ( $*m/(mpg))