My code works except variable s remains fixed to 20 when it should be changing depending on the values of input for variable x
Show older comments
Can someone help me with my code? I'm trying to calculate the cost (x), taxes (t), and shipping cost (s) but for some reason the shipping doesn't change with the parameters I put.
prompt='How many giant slinkys do u wanna buy? ';
x=input(prompt);
if x<=10;
x= 21.99*x;
elseif (11>=x)&(x<=50);
x=x*19.99;
elseif (51>=x)&(x<=100);
x= x*17.99;
else x >= 100;
x= x*15;
end
if x<=10;
s=10;
elseif (x>10)&(x<=20);
s=20;
elseif (x>20)&(x<=30);
s=30;
elseif (x>30)&(x<=40);
s=40;
elseif (x>40)&(x<=49);
s=50;
elseif (x>=50);
s=0;
end
disp('Cost will be ')
disp(x);
t=x+.095*x;
disp('sales tax')
disp(t);
disp('Shipping cost')
disp(s);
T=x+t+s;
disp('The total cost is')
disp(T)
2 Comments
Stephen23
on 2 Mar 2018
Make sure the user's input is a positive integer.
• 10 or fewer Slinkys cost $21.99 each.
• 11 to 50 Slinkys are $19.99 each
• 51 to 100 Slinkys are $17.99 each
• More than 100 Slinkys cost $15 each.
• Sales tax is 9.5%
• Shipping is $10 for each group of 10 Slinkys. For example: ◦ Shipping for 1 Slinky is $10; Shipping for 8 is also $0; Shipping for 10: $10. ◦ Shipping for 11 Slinkys is $20; Shipping for 15, also $20; Shipping for 20: $20. • Shipping is free for orders of 50 or more Slinkys
this is the homework problem idk if im doing something wrong with my code
Stephen23
on 2 Mar 2018
In the second set of decision statements you are not still not testing the original number that was input by the user, instead you are testing that number multiplied by the scaler. I don't know if this is what you want to do or not, but I suspect it isn't. If indeed you want to test the original input you can replace the c with the x in the second decision block (since you have now preserved the original input of x by assigning the calculation in the first decision block to a new variable).
Accepted Answer
More Answers (0)
Categories
Find more on Testing Frameworks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!