write a function called taxi fare that computes the fare of taxi ride. It takes two inputs : the distance in kilometers (d) and the amount of wait time in minutes (t). The fare is calculated like this
(the first km is $5)
(every additional km is $2)
and every minuteof waiting is $0.25.
Once a km is started.It counts as a whole( Hint: consider the ceil built in function). The same rule applies wait to times. You can assume that d>0 and t>= 0 but they are not necessarily integers. The function returns the fare in dollars. For example ,a 3.5-km ride with2.25 minutes of wait costs $11.75. Note that loops and if statement are neither necessary nor allowed.
Answers
Answered by
0
Given that,
The distance in kilometers (d) and the amount of wait time in minutes (t).
We need to find the fare in form of function
Using given data,
% function taking d and t as arguments
function fare = taxi_fare(d, t)
% taking the ceil values of d and t
d = ceil(d);
t = ceil(t);
% calculating fare using rules given
end
% sample run
fare = taxi_fare(3.5,2.25)[/tex]
Hence, This is required answer.
Answered by
0
Answer: %function is taxi_fare and input is d(km) and t(minutes)
function fare = taxi_fare(d,t)
%consider ceil as a built in function
d = ceil(d);
t = ceil(t);
fare = 5+[2*(d-1)]+(0.25*t);
end
Similar questions