Getting a script to continue to ask for a user specified input value until a certain input is entered.
Mostrar comentarios más antiguos
Hello, I first just want to say how helpful this site is. Anyway, I am trying to create a script where as soon as the script is run, it automatically goes back to the start and asks a user for a new input, and will terminate when the user enters 0 as the input value. Script is shown below for reference:
clear;clc;
x = input('Enter kilowatt-hour used, (Enter 0 to terminate): ');
if x <= 300
cost = 0.09*x;
elseif x <= 600
cost = 300*0.09 + 0.08*(x-300);
elseif x <= 1000
cost = 300*0.09 + 0.08*300 + 0.06*(x-600);
else
cost = 300*0.09 + 0.08*300 + 0.06*400 + 0.05*(x- 1000);
end
disp(['The total cost is ', num2str(cost), ' dollars'])
I have all the calculations done, I just need a bit of guidance for getting it to continually ask for an x=input (shown on second line) when the script file is run , and finally terminate when the user enters 0 when prompted for an input. Is there a relatively simple way of doing this?
Any help at all is greatly appreciated, Thanks.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Shifting and Sorting Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!