Need help with MATLAB
I've been having trouble with the following code. What's supposed to happen is you input a 5-digit string, and this program interprets it a way that's better explained by reading the code than by me explaining it here. Everything works right up until 'Invalid Rescue Day'. After that, nothing happens.
I should note that the section immediately after that, where you see rvn a couple of times, works partially, in that it calculates a value for rvn, but that's it; the else disp('Decoy message: Invalid rendezvous point') string doesn't work when it should.
Can anybody see anything wrong with this code?
code_str = input('Please enter a code to break:', 's');
digits = code_str - '0';
a = digits(1,1) .* digits(1,2) - digits(1,3);
if length(digits) ~= 5, disp('Decoy message: Not a 5-digit number.');
else sum(digits);
____if mod(sum(digits),2) == 1, disp('Decoy message: Sum is odd.');
____else a;
________switch a;
________case 1, day = 'Monday';
________case 2, day = 'Tuesday';
________case 3, day = 'Wednesday';
________case 4, day = 'Thursday';
________case 5, day = 'Friday';
________case 6, day = 'Saturday';
________case 7, day = 'Sunday';
________otherwise, disp('Decoy message: Invalid rescue day.');
____________if digits(1,4) > digits(1,5), rvn = digits(1,5)+1;
____________elseif digits(1,4) < digits(1,5), rvn = digits(1,5)-1;
____________else disp('Decoy message: Invalid rendezvous point.');
________________switch rvn
________________case 2, place = 'fountain';
________________case 7, place = 'large tree';
________________case 8, place = 'bridge';
________________otherwise, disp ('Decoy message: Invalid rendezvous point.')
____________________disp()
________________end
____________end
________end
____end
end
I should note that the section immediately after that, where you see rvn a couple of times, works partially, in that it calculates a value for rvn, but that's it; the else disp('Decoy message: Invalid rendezvous point') string doesn't work when it should.
Can anybody see anything wrong with this code?
code_str = input('Please enter a code to break:', 's');
digits = code_str - '0';
a = digits(1,1) .* digits(1,2) - digits(1,3);
if length(digits) ~= 5, disp('Decoy message: Not a 5-digit number.');
else sum(digits);
____if mod(sum(digits),2) == 1, disp('Decoy message: Sum is odd.');
____else a;
________switch a;
________case 1, day = 'Monday';
________case 2, day = 'Tuesday';
________case 3, day = 'Wednesday';
________case 4, day = 'Thursday';
________case 5, day = 'Friday';
________case 6, day = 'Saturday';
________case 7, day = 'Sunday';
________otherwise, disp('Decoy message: Invalid rescue day.');
____________if digits(1,4) > digits(1,5), rvn = digits(1,5)+1;
____________elseif digits(1,4) < digits(1,5), rvn = digits(1,5)-1;
____________else disp('Decoy message: Invalid rendezvous point.');
________________switch rvn
________________case 2, place = 'fountain';
________________case 7, place = 'large tree';
________________case 8, place = 'bridge';
________________otherwise, disp ('Decoy message: Invalid rendezvous point.')
____________________disp()
________________end
____________end
________end
____end
end
0
Comments