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!