![]() Otherwise an error message will be displayed telling the user they weren't following the directions. If both of these conditions are true, then the computer will pick a random number and see if the user wins. In the case of numbers, the answer is 1 if the values are not equal, and 0 if they. This modified version of the A08A includes extra checks to see if the user typed in a number in the bounds from 1 to 10, and then checks to see if the number is an integer. The operator is used to determine the inequality of two numbers or arrays. Common conditional tests are as follows: if N = M % check to see if N is equal to M if N > M % check to see if N is greater than M if N >= M % check to see if N is greater than or equal to M if N 10ĭisp( 'your number needs to be between 1 and 10')Įlseif rem(N,1) ~= 0 % the ~= symbol means "not equal" % the rem(a,b) function returns the % remainder of a/bĮlse % computer picks a random number between 1 and 10 Notice that the logic test to see if the numbers are equal uses two equal signs "=". If the numbers are not equal, then the user sees a frowny face. If they are, then the user sees a smiley face. well as whether or not they operate on arrays or scalars: & (AND operator) and (OR. imagining ex with someone else alternatives 13 Great Things About Scorpios That Capriconrs Like 1. The if statement then checks to see if the two numbers are equal. However, if you want to suppress and hide the MATLAB output for an. Some people just do not like Capricorn zodiac signs. The computer then generates a random integer also between 1 and 10 using the randi() function. Operator < - less than < - less than or equal to > - greater than > - greater than or equal to - equal - not equal to.% if the numbers match, the user wins! if N = MĪ simple code that prompts the user for a number between 1 and 10. MATLAB are: Note that the equal to relational operator consists of two signs (with no space. You can specify multiple conditions in an IF statement by using the logical boolean variables and operators & (and), (or) and (not). % computer picks a random number between 1 and 10 If the statement is false, it is assigned a value of 0. N = input( 'Pick an integer between 1 and 10: ') A0A.m - If statement % get number from user
0 Comments
Leave a Reply. |