My code works except variable s remains fixed to 20 when it should be changing depending on the values of input for variable x
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Oskore Mune
el 1 de Mzo. de 2018
Comentada: David Fletcher
el 2 de Mzo. de 2018
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 comentarios
Stephen23
el 2 de Mzo. de 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
el 2 de Mzo. de 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).
Respuesta aceptada
David Fletcher
el 1 de Mzo. de 2018
The value of x will have been changed by your first decision structure, so by the time you test it again in the second decision tree it will be much higher than it was originally since you have already scaled it up by a factor. I suspect that this isn't intentional and instead of changing x you want to reassign x to a new variable.
2 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!