Korn shell can kiss my ass.

airbornflghtairbornflght Houston, TX Icrontian
edited November 2007 in Science & Tech
Ok. I'm doing some programming (scripting..) inside of ksh. now when I was assigned this little project I laughed, thinking I'd have it done in 15 minutes..

Here is the assignment. Write a program that shows a menu with two choices, play, or quit. Then from there the program chooses a random number from 1-20 and then the user guesses until correct. From there the user must be offered the chance to replay. Otherwise just quit.

My problem is with korn shell's control structures and operators. They are becoming a pain in my ass. I'm starting to get mad because I keep getting errors. I'm way too used to Java.

Here is what I have, granted it won't run.
menu=0
x=0
while ((menu != 1 & menu != 2 & menu != 3 ))
do
clear screen
print "********************"
print "Welcome:\n\t1: Play game\n\t2: How To\n\t3: Exit"
if ((menu != 1 & menu != 2 & menu != 3 & x > 0))
       then
              print "\nInput must be 1, 2, or 3!"
       fi
print "Enter A Choice: \c"
read menu
print "\n*******************"
((x=x+1))
done
clear screen
case $menu in
1)
       #Pick Random Number
       #check if input equals q, if so exit
       #check if input is in range, if not get input again; alert user
       #check if input is equal to number, if not get input again; alert user
       #offer user chance to play again, if not exit
       #return to menu
2)
       print "The computer chooses a random number"
       print "It is between one and twenty"
       print "Try to guess that number"
       #return to menu
3)
       exit

This is all fairly sloppy but I'm trying to get it to work and it's not happening. the program will run right up until it tries to decide a case it says: Can someone help me get the cases working. good lord if I could do that then this program would be pretty much wrapped up.
syntax error: 'case' unmatched

Comments

  • CBCB Ƹ̵̡Ӝ̵̨̄Ʒ Der Millionendorf- Icrontian
    edited November 2007
    It's been awile for me, so I could be wrong, but shouldn't your 'menu' variable be indicated as either a string or as a numeral in every case instead of mixing and matching?
  • airbornflghtairbornflght Houston, TX Icrontian
    edited November 2007
    as far as I can tell. no. you just use the double parentheses to dictate math needs to happen. and if there is an string or character in the mix at that time you will have problems.
  • kryystkryyst Ontario, Canada
    edited November 2007
    I've never used korn, I use bash myself. However I'm pretty sure you need to preface every variable with a $ each time you recall it after the declaration.

    so
    while ((menu != 1 & menu != 2 & menu != 3 ))
    should be while (($menu != 1 & $menu != 2 & $menu != 3 ))

    as should
    if ((menu != 1 & menu != 2 & menu != 3 & x > 0))
    if (($menu != 1 & $menu != 2 & $menu != 3 & x > 0))
Sign In or Register to comment.