%============================================================================== % Selection statement examples %============================================================================== % Example: Write a program that checks if a user input number % matches a known value. % % Algorithm: % + Store a number % + Prompt user for a value % + Check if number matches % + Report results clear; clc; storedValue = 10; testValue = input('Enter a number: '); if _____________________________ disp('Hooray! You got the right value!'); end disp('Press any key to continue....');pause; %------------------------------------------------------------------------------ % Hmmm... not very friendly as programs go.... % + need to improve output % + perhaps warn if they don't match? clear; clc; storedValue = 10; testValue = input('Enter a number: '); if _____________________________ disp('Hooray! You got the right value!'); _____ disp('Whoops! Wrong number!'); end disp('Press any key to continue....');pause; %------------------------------------------------------------------------------ % Now, what about other values? Perhaps you want to test the sign % of a number instead, and you don't know about the built-in $sign$ function: clear;clc; disp('Welcome to my sign-testing program!'); testValue = input('Enter a number. I can handle it: '); % Test the sign of a number: if ________________________ disp('Your number is positive.') elseif ____________________ disp('Your number is negative.') elseif ____________________ disp('Your number is zero.') else ____________________ end disp('Press any key to continue....');pause; %------------------------------------------------------------------------------