필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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
Md.Sojon beg sojon
Md.Sojon beg sojon 2020년 7월 24일
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 2020년 7월 24일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

sixwwwwww
sixwwwwww 2013년 10월 29일
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
dpb
dpb 2013년 10월 29일
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.
sixwwwwww
sixwwwwww 2013년 10월 29일
yes it happens. Asker will be able to correct it by himself. Thanks for pointing out

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by