{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

HW7 #2

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

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

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)

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

View Full Document
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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern