Design a bounded number-guessing game
Scenario. A classroom game asks a player to guess a hidden whole number from 1 through 100.
Inputs. A valid hidden secret from 1 through 100 and one player entry in each round. The player may make at most seven entries. An entry is valid when it is a whole number from 1 through 100.
Rules and notation. Every entry consumes one round, including an invalid entry. After each entry:
- output
Invalid entrywhen it is outside the permitted domain; - otherwise output
Higherwhen the entry is below the secret; - output
Lowerwhen the entry is above the secret; or - output
Correct in n roundswhen it equals the secret, wherenincludes the successful round.
After seven unsuccessful rounds, output No more attempts and stop.
Assumptions. The secret is supplied by the exercise system and is not changed during play. No random-number algorithm is required.
Deliverable. Write modular pseudocode with a visible stopping condition. State the messages for secret 42 and entries 20, 60, 42.
Success criteria. A correct guess is included in the round count, no more than seven entries are read, every entry produces one message, and the stopping condition is explicit.
Increase the round count immediately after reading an entry. The number of rounds remaining then decreases on every iteration.