fprintf is outputting the wrong number, what's wrong with my code?
이전 댓글 표시
so to quickly summarize im trying to figure out how to make a budgeting code using the function program. the problem is that fprintf is outputting the wrong number. ill put the code below. what am i doing wrong?
function budget(x,y);
x = input('please give the budget for today:');
if isnumeric(x)
else
fprintf('Error: Input must be numeric.')
end
if isfinite(x)
else
fprintf('Error: Input must be a finite value.')
end
y = input('how much did you spend')
z = x-y;
if (y>x)
fprintf('the shopper went $%g over the budget.','z')
elseif (y>200)
fprintf('try to scale back the costs next week')
elseif (y<x)
fprintf('the shopper is $%g under budget','y')
elseif (x<=0)
fprintf('thats a great job budgeting')
elseif (y==x)
fprintf('the shopper is exactly on budget')
end
댓글 수: 5
jacob parente
2021년 3월 8일
"its just what they wanted me to do for my homework"
So your homework specifically asked for you to define a function with two totally pointless input arguments? Very ... unusual.
Or did it actually ask you to define a function which accepts two input arguments, to be used in the rest of the function?
jacob parente
2021년 3월 8일
Stephen23
2021년 3월 8일
"Create a function named budget that has one input and no outputs. The input will be the amount spent at the grocery store."
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!