1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Lady bird [3.3K]
3 years ago
12

Create a bash shell script for a number guessing game. Here are the requirements: a. Your program generates a random number betw

een 0 and 128 and keeps asking the user to guess the number until the user guesses it correctly. b. If the user guesses a number that is lower or higher than the number to be guessed then indicate that information to the user as a ‘low guess’ or a ‘high guess’ so that the user can get to the correct guess quicker. c. The program keeps track on number of guesses taken by the user to get to the correct guess. This is user’s score. d. Your program asks user for the name and adds user’s name and the score in a file that keeps track of the scores by various users. e. At the end of the game, the program displays the top 3 scores (lowest 3 scores) along with the name of the users to conclude the game. John 4 Sam 7 Tony 10

Computers and Technology
1 answer:
Damm [24]3 years ago
4 0

Answer:

Here is the bash shell script:

scorefile="scores_bash"

guess=-1

typeset -i n=0

echo -e "guess.bash - Guess a number between 0 to 128\n"

(( answer = RANDOM % 128 + 0 ))

while (( guess != answer )); do

n=n+1

read -p "Enter guess $n: " guess

if (( guess < answer )); then

 echo "Low guesss"

elif (( guess > answer )); then

 echo "High guess"

fi

done

echo -e "You guessed the number in $n guesses.\n"

read -p "Enter your name: " name

echo $n $name >> $scorefile

echo -e "\nScores"  

sort -n $scorefile

Explanation:

The program creates a scorefile as scores_bash to store the names and scores. Next the program initializes the guess with -1. guess is used to store the guess made by user and n is used to store the number of trials user took to guess the correct number. Next the program prompts the user to: Guess a number between 0 to 128 and generates random numbers from 0 to 128 and store it into answer.  Next the while loop keeps repeating until the user guesses the correct number. If the user guess is less than the correct answer then the program displays the message Low guess otherwise displays High guess. When the user guesses the correct number, the loop breaks and the message You guessed the number in $n guesses. is displayed where in place of $n the number of trials user take to guess the number is displayed. Next the user is asked to enter his name.

echo $n $name >> $scorefile statement adds the n which is the user score and name which is the names of user to the score file.  sort -n $scorefile  sorts the file in ascending order to display the lowest  scores. The screenshot of program with its output is attached.

You might be interested in
I am in desperate need to graduate. Overloaded with tons of online homework to be completed before the school year ends. I don't
Alenkinab [10]

What school do you go to?

8 0
3 years ago
When you select an object in the Visual Studio Designer, the object's size, color, text, and other characteristics are displayed
harina [27]

Answer:

the main window if that`s not correct sorry

Explanation:

3 0
3 years ago
What is the key function of a Scrum Master?
Reptile [31]

Answer:

The scrum master is the team role responsible for ensuring the team lives agile values and principles and follows the processes and practices that the team agreed they would use. The responsibilities of this role include: Clearing obstacles. Establishing an environment where the team can be effective.

Explanation:

8 0
4 years ago
What are some of the challenges that could arise from setting up a file management system on a computer?
Arisa [49]
It could fail, it would take a long time setting it up and aslo it could be easily hacked.
3 0
3 years ago
Image files contain metadata. Give three examples of this.<br> 1.<br> 2.<br> 3.
Elina [12.6K]

Answer:

Explanation:

We can add some metadata to an image or with some cameras when we take a photograph the camera gives some metadata to the image, for example, the camera brand, ISO, aperture, and shutter speed.

An image regularly has some metadata by default like dimensions, weight, and height.

We can sell photos on the internet, and we can add some keywords, description, and titles.

5 0
4 years ago
Other questions:
  • How does the browser display the same webpage whether you enter the URL or the IP address in the address bar? what system transl
    11·1 answer
  • A mobile device is freezing almost daily. The device remains powered on and the screen illuminated. The user restarts the device
    13·1 answer
  • Which of the following statements is true?
    12·1 answer
  • Create a class called Home that contains 4 pieces of information as instance variables: county (datatype string), street (dataty
    5·1 answer
  • We have a combinatorial logic function that can be decomposed into three steps each with the indicated delay with a resulting cl
    15·1 answer
  • This diagram shows who is responsible in preventing cyberbullying. A flowchart. Top box is labeled Cyberbullying can be prevente
    14·2 answers
  • Three batch jobs, A through E, arrive at a computer center at almost the same time. They have estimated running times of 10, 6,
    6·1 answer
  • Ashton assigned a string value to a variable. Which program statement should he use?
    7·1 answer
  • On an XBOX 360, what does it mean if you get 4 red rings on your console?
    5·1 answer
  • What is the full form of HTML​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!