Skip to main content

Practice ยท 3 of 5

Number guessing game logic

Implement int guesses(int secret, int maxAttempts) that simulates a player who guesses 1, 2, 3, ... in order. Return the attempt number on which the secret is guessed, or -1 if maxAttempts runs out first. guesses(4, 10) returns 4.

Difficulty: beginner

Back to lesson: Practice: Practice: Loops