How to continue an if statement after using the switch function

8 次查看(过去 30 天)
I imbedded a switch function into an if statement but I'm finding it hard to nest my next if statment to the previous one.If you run this code it will only work half way.
In this code use the number 332837840 (when asked to type in:)
% scd must be a 9 digit number.
scd = input('Type in: ','S');
conDIG = scd - '0';%converting to digits
scued =(conDIG(1)*conDIG(3))-conDIG(5);
if scued > 7 || scued < 1
disp('De')
else
switch scued
case 1
disp('M')
case 2
disp('T')
case 3
disp('W')
case 4
disp ('T')
case 5
disp ('F')
case 6
disp ('S')
case 7
disp ('S')
otherwise
disp('A')
if scued > 7 || scued < 1
mpt = conDIG(2)*conDIG(4)- conDIG(6);
else
disp('De')
if mod(mpt,3) ~= 0
rendzP = conDIG(8)- conDIG(9);
else
rendzP = conDIG(7)- conDIG(9);
if rendzP > 7 || rendzP < 1
disp('De')
else
switch rendzP
case 1
disp('b')
case 2
disp('l')
case 3
disp('r')
case 4
disp('a')
case 5
disp('b')
case 6
disp('l')
case 7
disp('D')
otherwise
disp('De.')
end
end
end
end
end
end

采纳的回答

Cris LaPierre
Cris LaPierre 2021-2-21
编辑:Cris LaPierre 2021-2-23
Right now, your second if statement is part of the otherwise case of the switch statement. If you want it to execute after the switch statement, you need to move the closing end to the end of the switch statement.
if ...
code
else
switch var
case 1
code
case 2
code
otherwise
code
end % end of switch statement
end % end of first if statement
if ...
code
end % end of second if statement

更多回答(0 个)

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by