Advertisement
Guest User

260708939

a guest
Feb 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.48 KB | None | 0 0
  1. #!/bin/bash
  2. #Andy Jung 260708939
  3. #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.
  4. i=0
  5. if [[ -r Data.pg ]]
  6.     then echo "Data.pg exists. Parsing Data.pg file."
  7.     else
  8.     echo "Data.pg does not exist. Creating Data.pg file."
  9.  
  10.         while [[ i -lt 10 ]];
  11.             do
  12.                 n1=$[($RANDOM % 50)+90]
  13.                 echo $n1 >> Data.pg
  14.                 ((i++))
  15.             done
  16.  
  17. fi
  18.  
  19. #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
  20.  
  21. average=0
  22.  
  23. #Set guess to -1 before updating value by user
  24. guess=-1
  25. #Set success to 0, will set to 1 if user guesses successfully so that Data.pg can be updated later.
  26. success=0
  27. #Set initial number of attempts
  28. attempts=1
  29. actualnumber=0
  30.  
  31. while [[ attempts -le 3 ]];
  32. do
  33.     read -p "Guess Number? $num" guess
  34.     if [[ $guess -eq $actualnumber ]]; then
  35.     echo "Well Done. You took $attempts tries to guess. Average tries is $average"
  36.     success=1
  37.     break
  38.     else
  39.     echo "Incorrect guess. Try again."
  40.     ((attempts++))
  41.     fi
  42.    
  43. done
  44.  
  45. echo "You took $attempts attempts"
  46. # 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
  47. if [[ $success -eq 1 ]]; then
  48. echo "Updating Data.pg with your guess number and the new average"
  49. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement