Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
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