Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7698225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:11:34+00:00 2026-05-31T22:11:34+00:00

I am having a logic issue with my UNIX number guessing game. The menu

  • 0

I am having a logic issue with my UNIX number guessing game. The menu system works just fine (1 for play, 2 to quit, defensive response otherwise). But once in the game I am getting an output as follows:

  1. OPTIONS:
  2. (1. Play)
  3. (2. Exit)
  4. Enter number 1 or 2.
  5. 1
  6. Please enter you’re guess.
  7. 5
  8. pgm01[43]: [5: not found [No such file or directory]
  9. pgm01[47]: [5: not found [No such file or directory]
  10. Yay!!! 5 is the right number!!!
  11. Your total number of tries were 0.

Here is the code (FYI this is in the KSH shell). I am guessing I have some sort of syntax error somewhere…

  #!/bin/ksh
  # CS2351 - UNIX Programming
  # Program 1

  x=$RANDOM%100+1
  tries=0
  guessInt=0
  userOption=0

  while ((1==1))
  do
     print "Welcome to the UNIX Number Guessing Game!"
     print "A random number between 1 and 20 has been selected."
     print "===========\nDirections: \n==========="
     print "1. Enter your guess. The program will tell you if it is high or low."
     print "2. The program will tell you if it is high or low."
     print "3. Change your guess."
     print "4. The computer will tell you how many guesses you had."
     print "=======\nOPTIONS\n======="
     print "1: Play \n2: Exit"
     print "Enter number 1 or 2."

     "Enter number 1 or 2."

     read userinput
     case "$userinput" in

     1)
        break;;
     2)
        print "Quitting program!!!"
        exit;;
     *)
        print "The input $userinput is invalid."
        print "Returning to main menu..."
        print "\n\n\n";;
     esac
  done

  print "Please enter you're guess."
  read guessInt
  while (($guessInt != "q"));
  do
     if [$guessInt -lt $x];
     then
        print "Your guess is too low, try again! (q to quit)."
        tries=tries+1
     elif [$guessInt -gt $x];
     then
        print "Your guess is too high, try again! (q to quit)."
        tries=tries+1
     else
        print "Yay!!! $guessInt is the right number!!!"
        break
     fi
  done

  print "Your total number of tries were $tries."
  exit

Any insight into this issue is appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:11:35+00:00Added an answer on May 31, 2026 at 10:11 pm

    As far as I can tell, you need double brackets for conditionals and some whitespace is significant. You need something like:

    if [[ $guessInt -lt $x ]]; then
    

    tries should also start at 1, since there’s no way you can win without guessing first.

    You should also read guessInt again inside the while loop if their guess is wrong, because if you guess wrong the first time, it will just repeat forever (since the value of $guessInt doesn’t change between iterations of the loop).

    Take a look at these shell script syntax examples; it’s got a lot of bash stuff but there’s some decent coverage of ksh as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a hangman game. I'm having a logic fail, both with myself and
I'm having an issue with a Struts 1 form, which contains a logic:iterate in
I am having an issue with the following logic - because the ajax request
I am having a dilemma in the logic of this particular issue. Forgive me
I am having an issue with creating a pop-up window. I have a game
I'm having problems with a mammoth legacy PL/SQL procedure which has the following logic:
I'm having a great deal of difficulty trying to figure out the logic behind
My colleagues and I were having a discussion regarding logic in enums. My personal
I’m having a little Architecture problem. In my project I have a Business Logic
I'm having the following issue: I have a trigger on a table A, whose

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.