Reputation: 1
Function 1:
function [x,y]=func1(x,y)
x = input('Enter how many tickets you would like: ');
y = input('Enter what level you would like to sit in: ');
end
Function 2:
function [z] = func2(x,y)
switch l
case y==1
z = 500*x;
case y==2
z = 350*x;
case y==3
z = 200*x;
end
Function 3:
function [x,y,z]=func3(x,y,z)
[x,y]=func1(x,y);
z=func2(x,y);
fprintf('It will cost $%.2f for %d tickets in level %d.','z','x','y');
end
I'd like to call upon these three functions in succession (this is how I tried to do it):
func1(x,y)
func2(x,y)
func3(x,y,z)
I'd like for only three lines to be printed (except I want the actual calculation to be printed rather than x,y,z):
Enter how many tickets you would like:
Enter what level you would like to sit in:
It will cost $z for x tickets in level y.
The first of these two lines come out fine, but the third prints random numbers in place of x,y,z. What am I doing wrong?
Upvotes: 0
Views: 47
Reputation: 4768
Your fprintf
statement should be
fprintf('It will cost $%.2f for %d tickets in level %d.',z,x,y);
you want the values stored in x, y, z
, not the strings 'x', 'y', 'z'
.
Upvotes: 3