Question

In: Computer Science

Linux: I have a working script but need a high/low comparison added to each guess by...

Linux: I have a working script but need a high/low comparison added to each guess by the user.

choice=$(( $RANDOM % 100 + 1 ))

read -p 'Please choose a number from 1-100:' variable

while [ $variable -ne $choice ];
do
echo "Your choice was wrong. Please try again."
read -p 'Please choose a number from 1-100:' variable
done

echo "You chose correctly!!!"

The comparison is the variable chosen by the game is supposed to be guessed by the user. Because the choices range from 1-100, I need the script to tell the user if they chose too high or too low until the user makes the correct choice.

Solutions

Expert Solution

Code:

choice=$(( $RANDOM % 100 + 1 ))

variable=0

while [ $variable -ne $choice ];

do

read -p 'Please choose a number from 1-100:' variable

# if variable is greater than choice

if [ $variable -gt $choice ]

then

echo "Your choice is too high. Please try again"

# if variable is less than choice

elif [ $variable -lt $choice ]

then

echo "Your choice is too low. Please try again"

# if variable equals choice

else

echo "You chose correctly!!!"

fi

done

Code Screenshot:

Sample Output:


Related Solutions

I need an Arduino uno code to measure high low levels with hcsr04 of a tank...
I need an Arduino uno code to measure high low levels with hcsr04 of a tank and display it on i2c 20x4 lcd.
I am attempting to write a script using bash on Linux. My program must save the...
I am attempting to write a script using bash on Linux. My program must save the long list format of the parent directory to a text file. Then, it must print how many items are in this parent directory. Then, it must sort the file in reverse order and save it to a different text file. I understand that the parent directory is accessed using cd .., and I understand that a file can be written to by echoing and...
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given...
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given only two integer numbers from command line arguments and computing their multiplication. If two integer numbers are not given, print “Wrong Input” on your screen. Note that, the number of arguments is known when the script runs. Take a screenshot showing your shell program and its execution step. Design a shell program to remove all the shell programming files ending with sh on your...
.How do you rank (high or low) the diversity issues in comparison to the other ethical...
.How do you rank (high or low) the diversity issues in comparison to the other ethical issues in your organization?
I would guess that each of you have been to a fast-food restaurant. Think about all...
I would guess that each of you have been to a fast-food restaurant. Think about all of the aspects of the operation procedures used to take, process, and fill an order and deliver the order to the customer. Based on what you have observed during your visit to one of these restaurants, identify at least three variable and three fixed costs. Can you identify any potential mixed costs? Why is the restaurant willing to sell a large drink for only...
In international business, discuss how Hall’s concept of high and low context comparison of cultures impacts...
In international business, discuss how Hall’s concept of high and low context comparison of cultures impacts businesses in different country settings. Compare any four dimensions, thus identifying how each would manifest (i.e., visually or verbally, as in negotiations) itself in a business situation.
Revision Question 1 on Linux. Please briefly explain the shell script given. a) You have just...
Revision Question 1 on Linux. Please briefly explain the shell script given. a) You have just logged in and have a directory called "images" in your home directory containing the following files: favicons login.png logo.png newlogo.png where "favicons is a directory and contains the files favicon.ico favicon.gif favicon.png favicon.jpg Describe the results you would expect when executing the following shell commands: i) ls images/*og* | wc -1 ii) ls -ld images/* iii) rmdir images/favicons iv) cp images/*/*png images v) rm...
what is the junction low (i need traffic flow not current), plees i also need a...
what is the junction low (i need traffic flow not current), plees i also need a reference . thank you
A C PROGRAM *Edit/Update I do not need the file loading script, but I am not...
A C PROGRAM *Edit/Update I do not need the file loading script, but I am not against it being included in the answer* I must read off of an excel file (comma separated) to input five different things for a book, all comma separated, there are 360 books in the file. The book title, author, ISBN number, number of pages, and finally the year it was published. Now some of the ISBN or Pg numbers may be missing and will...
I need a reply for this comment: "In a perfect world if I was working for...
I need a reply for this comment: "In a perfect world if I was working for a local hospital or doctors office, I believe that the hospital/office would need to make and keep their employees happy. This can be with incentives and good benefits. However, a main reason that I would keep a position is the leadership of co-workers, management, and the doctors. This would make work pleasant and would flow into employees working better with customers and patients. The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT