SUNY Geneseo Department of Mathematics
Wednesday, March 25
Math 230 02
Spring 2015
Prof. Doug Baldwin
>> n = input( 'Enter a 1-digit number ' );
Enter a 1-digit number 17
>> while n > 9
+ n = input( 'Too big! Try again ' );
+ end
Too big! Try again 10
Too big! Try again 236
Too big! Try again 3
n
n =
3
>> round( 3.4 )
ans =
3
>> round( 3 )
ans =
3
>> while abs(n) > 10 && n ~= round(n)
+ n = input( 'Try again ' );
+ end
% No prompt for more, this accepts 3 as 1-digit
>> n = input( 'Enter a 1-digit number ' );
Enter a 1-digit number -3.5
>> while abs(n) > 10 && n ~= round(n)
+ n = input( 'Try again ' );
+ end
% No prompt, so it also accepts -3.5 as 1-digit
% correct number: abs(n) < 10 and n = round(n)
% while "incorrect number"
>> while abs(n) >= 10 || n ~= round(n)
+ n = input( 'Try again ' );
+ end
Try again 1.5
Try again 12
Try again 10
Try again 6
% Seems to work
% What if n is complex?
>> n = 3+2i
n =
3.0000 + 2.0000i
>> while abs(n) >= 10 || n ~= round(n)
+ n = input( 'Try again ' );
+ end
% No prompt for more input, so Matlab apparently accepts 3 + 2i as a 1-digit number