Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # @author LinChuWen
- # course: Operating Systems Lab
- # First Version: 2016.09.23
- # Last Version: 2016.09.26
- min=0
- max=100
- start=$min
- end=$max
- SetTarget(){
- printf "set a target: "
- read target; ans=$target
- Check;
- }
- Check(){
- if [ $ans -le $min ]; then
- echo "WRONG INPUT! your target must greater then $min"
- SetTarget;
- elif [ $ans -ge $max ]; then
- echo "WRONG INPUT! your target must less then $max"
- SetTarget;
- fi
- }
- Hello(){ echo "Welcome to the summoner's rift!"; }
- Hello;
- if [ $1 ]; then
- ans=$1; Check;
- else SetTarget; fi
- while [ $ans -lt $max ]; do
- printf "Guess a number between $start and $end: "
- read input
- if [ $input -gt $max ] || [ $input -lt $min ]; then
- echo "WRONG INPUT! range: $min ~ $max"
- elif [ $input -gt $ans ]; then
- if [ $input -lt $end ]; then
- end=$input; fi
- elif [ $input -lt $ans ]; then
- if [ $input -gt $start ]; then
- start=$input; fi
- else
- echo "BINGO! the answer is $ans !"
- break
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement