{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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)
Image of page 1

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern