how to make if accept letters?
Mostrar comentarios más antiguos
i know about 'if' code, but what i dont understand is why it tells me error?
error: 'y' undefined near line 33 column 16
error: called from
Code_6 at line 33 column 5
nam = input('Enter name: ', 's');
adrs = input('Enter address: ', 's');
num = input('Enter amount of purchase: $');
pur = input('Enter type of purchase (L for Laptop / D for Desktop): ', 's');
fprintf('\n')
switch pur
case {'L' 'l'}
disp('You have choosen Laptop as your type of puchase')
if num <250
disc = (0 / 100) * num;
net = num - disc;
elseif num <570
disc = (5 / 100) * num;
net = num - disc;
elseif num <1000
disc = (7.5 / 100) * num;
net = num - disc;
elseif num >1000
disc = (10 / 100) * num;
net = num - disc;
endif
fprintf('Name: %s\n', nam)
fprintf('Address: %s\n', adrs)
fprintf('Net amount: $%.2f \n', net)
#promt user to continue or not
yesno = input('Do you wish to continue purchase? (y/n)', 's')
fprintf('\n')
if yesno = y;
Code_6
else
disp('You have exit purchase screen, Goodbye.')
endif
1 comentario
per isakson
el 28 de Nov. de 2020
Editada: per isakson
el 28 de Nov. de 2020
Firstly, replace endif by end. And it's a good habit to have an else-clause in every if-end statement.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre MATLAB 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!