필터 지우기
필터 지우기

Function might not be used error

조회 수: 1 (최근 30일)
Ella
Ella 2023년 3월 8일
편집: VBBV 2023년 3월 8일
function[error, tip, amount]=CalcTip(bill,serv)
%return error code of zero
error=0;
%cal tip based on level of service using switch..
switch serv
case 1
%poor(5 percent no min)
tip=(5/100)*bill;
amount=tip+bill;
case 2
%fair(10 percent min of £1)
tip=(10/100)*bill;
if tip<1
tip=1;
end
amount=bill_tip;
case 3
%good(15 percent min of £2)
tip=(15/100)*bill;
if tip<2
tip=2;
end
amount=bill+tip;
otherwise
tip=0;
amount=bill;
error=1; %because we now have an error
end
end
error for the Calctip says function might not be used
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2023년 3월 8일
How did you run your code/the function?
Ella
Ella 2023년 3월 8일
I saved it as CalcTip.m then put [error,tip,amount]=CalcTip(50,2) into Command Window

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

답변 (2개)

VBBV
VBBV 2023년 3월 8일
amount=bill-tip;% typo with operator
There is a typo for the operator in the above line which presumably makes Matlab think it as unused function
  댓글 수: 1
VBBV
VBBV 2023년 3월 8일
편집: VBBV 2023년 3월 8일
It is present in case 2, and instead shown as
amount=bill_tip;% typo

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


David Hill
David Hill 2023년 3월 8일
[e,t,a]=CalcTip(100,3)
e = 0
t = 15
a = 115
[e,t,a]=CalcTip(100,4)
e = 1
t = 0
a = 100
[e,t,a]=CalcTip(100,5)
e = 1
t = 0
a = 100
[e,t,a]=CalcTip(100,2)
e = 0
t = 10
a = 110
function[error, tip, amount]=CalcTip(bill,serv)
%return error code of zero
error=0;
%cal tip based on level of service using switch..
switch serv
case 1
%poor(5 percent no min)
tip=(5/100)*bill;
amount=tip+bill;
case 2
%fair(10 percent min of £1)
tip=(10/100)*bill;
if tip<1
tip=1;
end
amount=bill+tip;%bill+tip
case 3
%good(15 percent min of £2)
tip=(15/100)*bill;
if tip<2
tip=2;
end
amount=bill+tip;
otherwise
tip=0;
amount=bill;
error=1; %because we now have an error
end
end

카테고리

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