QP4 - coordinates (0,0) and maximum coordinates (9,9)....

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Quiz Program #4 Program Description The Fibonacci sequence begins as follows: 1, 1, 2, 3, 5, 8, 13, 21, 34, . .. Essentially, the first two numbers are one, and each subsequent number is the sum of the two previous numbers. Write a program that prompts the user to enter a positive integer. If the user enters 0 or a negative integer, reprompt the user to enter again. Continue doing so until the user enters a positive integer. Then, for the given positive integer, n , calculate the n th number in the list above, also known as the n th Fibonacci number. Sample Run (User input in bold and italics) Enter n. -3 Sorry, that is not a positive integer. Enter n. 0 Sorry, that is not a positive integer. Enter n. 8 The 8 Fibonacci number is 21. A More Difficult Optional Practice Program Write a program that originally generates a random spot on a x-y grid with minimum
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: coordinates (0,0) and maximum coordinates (9,9). Then, prompt the user for a random guess as to the secret grid location. If the user gets it on the nose, print out a congratulatory message. Otherwise, tell them which direction they must move in to get to the point. We will consider moving in the positive x direction as going East and moving in the positive y direction as going North. (Just use N, S, E and W. Sometimes you will print out two directions for movement, other times only one.) Sample Run (User input in bold and italics) Enter your guess for x and y. 3 5 This is not correct. You need to move NW. Enter your guess for x and y. 1 7 This is not correct. you need to move S. Enter your guess for x and y. 1 6 You are correct! The secret location was 1,6....
View Full Document

Ask a homework question - tutors are online