fprintf is outputting the wrong number, what's wrong with my code?
Show older comments
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 Comments
jacob parente
on 8 Mar 2021
"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
on 8 Mar 2021
Stephen23
on 8 Mar 2021
"Create a function named budget that has one input and no outputs. The input will be the amount spent at the grocery store."
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!