Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # bash based guessing game.
- # Define the game function
- function play_game() {
- echo "Welcome to the game!"
- echo "Guess a number between 1 and 100:"
- secret_number=$((1 + RANDOM % 100))
- attempts=0
- while true; do
- read -p "Enter your guess: " guess
- ((attempts++))
- if [[ $guess -eq $secret_number ]]; then
- echo "Congratulations! You guessed the secret number in $attempts attempts."
- break
- elif [[ $guess -lt $secret_number ]]; then
- echo "Too low, try again."
- else
- echo "Too high, try again."
- fi
- done
- }
- # Call the game function
- play_game
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement