HW7 #2 - elseif guess>=num-3&guess<=num+3...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 %Engineering 6, Spring 2004, Problem 7.2 %Ryan Uy, 2509 %Section B05, Tues. 3-4 num = floor((rand*15)+1) %create a random number between 1 and 15 by multiplying by 15, adding 1, and flooring guess = input('Guess a number from 1 to 15: ') if guess==num %if user's guess equals the number, user wins fprintf('You guessed it!') elseif guess>=num-1&guess<=num+1 %conditional is entered only if guess~=num, therefore print statement fprintf('Close, but no cigar. The number was %.0f.',num)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: elseif guess>=num-3&guess<=num+3 %conditional is entered only if guess isn't within 1, therefore print fprintf('Nice try, but the number was %.0f.',num) else %conditional is entered only if guess isn't within 3, therefore print statment is executed fprintf('Stay away from the casinos. The number was %.0f.',num) end Sheet1 Page 2 %get user's guess %is executed if guess is within 1 %statement is executed if guess is within 3 %if no conditionals are met...
View Full Document

This note was uploaded on 01/22/2011 for the course ENG 006 taught by Professor Lagerstrom during the Spring '06 term at UC Davis.

Page1 / 2

HW7 #2 - elseif guess>=num-3&guess<=num+3...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online