Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

c shell is kicking my butt, I need help


  • Please log in to reply

#1
twilightgirl

twilightgirl

    New Member

  • Member
  • Pip
  • 1 posts
hi!! I am taking a class in unix and just can't manage to get my hangman game working. I'll paste it what I have written thus far, and this much is working fine. But I can't figure out how to make it say Yay! You got it! if the person guesses the word.

Thanks so much for any assistance~!!!!

#!/usr/bin/csh

@ n = `date +%S * date +%S * date +%M`
set wrd = `tail -$n /usr/dict/words | head -1
## I was using this to generate a random word, but I think that I need a better system, any ideas?`
echo "Let's play hangman"
@ x = 10
@ lettercount = `echo $wrd | wc -m`
while ($x >= 1)
echo "Type WORD if you want to guess a word, and LETTER if you want to guess a letter."
set LorW = $<
echo $LorW | grep '^WORD$' > /dev/null
set wantword = $status
echo $LorW | grep '^LETTER$' > /dev/null
set wantletter = $status

if ($wantword == 0) then
echo -n "The word has $lettercount letters in it. Well, what do you think it is?"
set guessedword = $<
set y = $wrd
set yy = $guessedword
if ($x == $y) then
echo "YOU WIN\!"
else
@ x = $x - 1
echo "Sorry, try again. You have $x guesses left"
endif
else if ($wantletter == 0) then
echo -n "The word has $lettercount letters in it. What letter do you think is in it? "
set guessedletter = $<
echo $wrd | grep $guessedletter > /dev/null
set yes = $status
if ($yes == 0) then
echo "Yes, $guessedletter is in the word"
else
@ x = $x - 1
echo "Sorry, try again. You have $x guesses left"
endif
else
echo "You tried to pick something other than LETTER or WORD"
endif
end
echo "The word was $wrd Better luck next time."
  • 0

Advertisements


#2
Ojoshiro

Ojoshiro

    Member

  • Member
  • PipPipPip
  • 146 posts
If your code downhere works, as you said, you should replace the:
echo "YOU WIN\!"
line with
echo "Yay\! You got it\!"
and that should do it.

Otherwise you lied and your code thus far didn't work.
If so, I'll empty your /dev/null ! :tazz:

Bye!
Ojo
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP