Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Andy Jung 260708939
- #Checks for Data.pg. If it does not exist, it will create a loop 10 times and input 10 random numbers, adds 90 as an encrypting method so that user cannot directly find the numbers.
- i=0
- if [[ -r Data.pg ]]
- then echo "Data.pg exists. Parsing Data.pg file."
- else
- echo "Data.pg does not exist. Creating Data.pg file."
- while [[ i -lt 10 ]];
- do
- n1=$[($RANDOM % 50)+90]
- echo $n1 >> Data.pg
- ((i++))
- done
- fi
- #parses the Data.pg file, and creates the number average which will be evaluated against the user's guess. Also sets average number of guesses, 0 if there are no previous guesses
- average=0
- #Set guess to -1 before updating value by user
- guess=-1
- #Set success to 0, will set to 1 if user guesses successfully so that Data.pg can be updated later.
- success=0
- #Set initial number of attempts
- attempts=1
- actualnumber=0
- while [[ attempts -le 3 ]];
- do
- read -p "Guess Number? $num" guess
- if [[ $guess -eq $actualnumber ]]; then
- echo "Well Done. You took $attempts tries to guess. Average tries is $average"
- success=1
- break
- else
- echo "Incorrect guess. Try again."
- ((attempts++))
- fi
- done
- echo "You took $attempts attempts"
- # once the guess is successful, will update Data.pg with number of guesses, and puts user's guess at top and moves the list of numbers down, removing the last number
- if [[ $success -eq 1 ]]; then
- echo "Updating Data.pg with your guess number and the new average"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement