Guessing Game Functions:
-
generate_secret_number() Purpose: Generate a random secret number for the player to guess. Parameters: None. Return Type: u32 (unsigned 32-bit integer). Behavior: Returns a random integer between 1 and 100 (inclusive).
-
prompt_guess() Purpose: Prompt the user to input their guess. Parameters: None. Return Type: u32 (unsigned 32-bit integer). Behavior: Reads a line of input from the user and parses it into an integer. If the input cannot be parsed or is out of range (not between 1 and 100), it prompts the user again until a valid guess is provided.
-
check_guess(guess: u32, secret_number: u32) -> Ordering Purpose: Compare the player's guess with the secret number. Parameters: guess: The player's guess (unsigned 32-bit integer). secret_number: The secret number generated by the game (unsigned 32-bit integer). Return Type: Ordering enum variant. Behavior: Compares the player's guess with the secret number and returns: Ordering::Less if the guess is less than the secret number. Ordering::Greater if the guess is greater than the secret number. Ordering::Equal if the guess is equal to the secret number.
-
print_result(result: Ordering, secret_number: u32) Purpose: Print the result of the player's guess. Parameters: result: The result of comparing the guess with the secret number (Ordering enum variant). secret_number: The secret number generated by the game (unsigned 32-bit integer). Return Type: None. Behavior: Prints a message to the console based on the result of the comparison: "Too low!" if the guess is less than the secret number. "Too high!" if the guess is greater than the secret number. "Congratulations! You guessed the number correctly: [secret_number]" if the guess is equal to the secret number.