Clear Filters
Clear Filters

Writing a script file for cost of a telephone call according to the following price schedule:

1 view (last 30 days)
The problem is to write a script that will calculate the cost. I understand that it is a loop problem. I'm lost as to how to define the time. I believe that it has to be converted to 24 hr format to use greater than less than etc.. but any help would be grateful.
  5 Comments
Md.Sojon beg sojon
Md.Sojon beg sojon on 24 Jul 2020
Write a program in a script file that calculates the cost of mailing a small package according to the following price schedule
Md.Sojon beg sojon
Md.Sojon beg sojon on 24 Jul 2020
Write a program in a script file that calculates the cost of mailing a small package according to the following price schedule:
Type of service
Weight more than 0 kg to 1kg
Weight more than 1 kg to 5kg
Ground
RM1.50
RM1.50+RM0.50 for each kg or fraction of a kg above 1kg.
Air
RM3.00
RM3.00+RM0.90 for each kg or fraction of a kg above 1kg.
Overnight
RM18
RM18.00+RM6.00 for each kg or fraction of a kg above 1kg.
The program asks the user to enter the weight and the type of service. The program then displays the cost. If a weight larger than 5kg is entered a message “Service is not available for packages that weigh more than 5kg” is displayed. Run the program and enter 0.25, 3.2, and 10 kg for Ground and Air service, and 1, 4.1 and 6.5 kg for Overnight service.

Sign in to comment.

Accepted Answer

sixwwwwww
sixwwwwww on 29 Oct 2013
Dear Andrew, here is the code for your question:
calltime = input('Enter call time(day, evening, night): ', 's');
callduration = input('Enter call duration: ');
callduration = round(callduration);
AboveThirty = 0;
TentoThirty = 0;
OnetoTen = 0;
TotalCost = 0;
if callduration > 30
AboveThirty = callduration - 30;
TentoThirty = 20;
OnetoTen = 10;
elseif callduration > 10 && callduration <= 30
TentoThirty = callduration - 10;
OnetoTen = 10;
else
OnetoTen = callduration;
end
switch calltime
case 'day'
OnetoTen = OnetoTen * 0.1;
if TentoThirty ~= 0
TentoThirty = TentoThirty * 0.08 + 1;
end
if AboveThirty ~= 0
AboveThirty = AboveThirty * 0.06 + 2.6;
end
TotalCost = OnetoTen + TentoThirty + AboveThirty;
case 'evening'
OnetoTen = OnetoTen * 0.07;
if TentoThirty ~= 0
TentoThirty = TentoThirty * 0.05 + 0.7;
end
if AboveThirty ~= 0
AboveThirty = AboveThirty * 0.04 + 1.7;
end
TotalCost = OnetoTen + TentoThirty + AboveThirty;
case 'night'
OnetoTen = OnetoTen * 0.4;
if TentoThirty ~= 0
TentoThirty = TentoThirty * 0.03 + 0.4;
end
if AboveThirty ~= 0
AboveThirty = AboveThirty * 0.02 + 1;
end
TotalCost = OnetoTen + TentoThirty + AboveThirty;
otherwise
disp('Invalid call time')
end
fprintf('Call cost is: %f\n', TotalCost)
I hope it helps. Good luck!
  16 Comments
dpb
dpb on 29 Oct 2013
There's still a logic/implementation error as compared to the program requirements...and that one isn't missing, it's just not what was asked for.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!