Function might not be used error
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
VBBV
el 8 de Mzo. de 2023
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
David Hill
el 8 de Mzo. de 2023
[e,t,a]=CalcTip(100,3)
[e,t,a]=CalcTip(100,4)
[e,t,a]=CalcTip(100,5)
[e,t,a]=CalcTip(100,2)
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
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!