Sonoma State University
Department of Computer Science
CS-210: Introduction to Unix
Exercise 12: BASH scripts

Objective:

Write a number guessing game using the BASH scripting language.

Specifications:

  • Your program should be named "guess.sh".
  • Your program should choose a random integer between 1 and 1000 inclusive.
  • Your program should prompt the user to enter an integer between 1 and 1000 inclusive.
  • Your program should validate the user's input to ensure it is a valid, positive integer. If it is NOT a valid positive integer, prompt the user to try again (and don't count the invalid input as a guess).
  • If the user's input equals the random integer chosen by the computer output, "You guessed my number!"
  • If the user's input is lower than the random integer chosen by the computer output, "Higher. Guess my number again: "
  • If the user's input is higher than the random integer chosen by the computer output, "Lower. Guess my number again: "
  • Your program should prompt the user to guess the correct number no more than 10 times. If the user fails to guess the correct number after the tenth try, please output what the random number was. For example: "My number was 504."

Hints:

  • You are welcome to review and run the the example BASH program I wrote to choose random numbers and prompt for user input.

Submission Instructions:

  • Please submit "guess.sh" to Canvas.

Exercise 12 Rubric

CRITERIA RATINGS POINTS
BASH looping Proficient
2 points

Student's program uses the BASH while or until statement to prompt the user to guess the correct number.
Satisfactory
1.4 points

Student's program prompts the user ten times to enter a correct guess. No BASH while or until loops are utilized.
Needs Improvement
1 point

Student's program fails to grant the user ten guesses to determine the correct number.
Below Expectation
0 points

No solution submitted.
2 points
Random number Proficient
1 point

Student's program chooses a random integer between 1 and 1000 inclusive.
Satisfactory
0.7 points

Student's program generates a random integer outside the range of 1 to 1000 inclusive.
Needs Improvement
0.25 points

Student's program does not generate a random number but instead uses a hard-coded integer constant instead.
Below Expectation
0 points

No solution submitted.
1 point
Hints Proficient
2 points

Student's program provides a correct hint to the user to enter a number higher or lower than the user's previous guess depending on the random number the program selected.
Needs Improvement
0.5 points

Student's program prompts the user to enter another guess but does not provide any hints such as "higher" or "lower" than previous guess.
Below Expectation
0 points

No solution submitted.
1 point
User input Proficient
2 points

Student's program uses a regular expression to verify that the user's input is a valid non-negative integer.
Satisfactory
1.4 points

Student's program uses a regular expression to verify that the user's input is a valid non-negative integer but there are logical or syntax errors with the regular expression which cause it to fail.
Needs Improvement
1 point

Student's program does not validate user input to determine if the user entered a valid positive integer.
Below Expectation
0 points

No solution submitted.
2 points
Syntax or run-time errors Proficient
2 points

Student's program runs on Blue without syntax or run-time errors.
Satisfactory
1.33 points

Student's program contains one syntax or run-time error when the program is run on Blue.
Needs Improvement
0.67 points

Student's program contains two or three syntax or run-time error when the program is run on Blue.
Below Expectation
0 points

No solution submitted.
2 points
Total points: 8