Beginner Scripting Issue

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:
    The object is to enter a number, then have another classmate guess the entered number.

  2. Relevant commands, code, scripts, algorithms:
    I am trying to use an if-then-else statement to accomplish my goal

  3. The attempts at a solution (include all code and scripts):
    #! /bin/csh
    echo "Please select a number to be guessed"
    read num1
    1:
    echo "Please guess a number"
    read num2
    if (num2 == num1) then

     echo "Congratulations!! You have guessed correctly!"
    

else
echo "Sorry, but that number is incorrect."
goto 1
endif

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Washtenaw Community College, Ann Arbor MI, USA, Doug Cox, CIS 121

<Hoping I did the template correctly>

The problem I am encountering is that no matter what number I enter, it always echos "Sorry, but that number is incorrect" even if I enter, say 11, for both num1 and num2. And yes, I am a complete coding noob. xD

In my cshell there is no read build-in.

As I remember, the way to read is:

set num1 = $<

In any case when you access the values of num1 and num2, they are variables, and should be referenced as $num1 and $num2

i.e.

if ( $num2 == $num1 )

I'm struggling to understand why anyone would teach c-shell... it really is dreadful.

Thanks for the reply scottn,

I think I understand what you said so I changed my coding to the following:

#! /bin/csh
echo "Please select a number to be guessed"
set num1 = $<
1:
echo "Please guess a number"
set num2 = $<
if ( $num2 == $num1 ) then

    echo "Congratulations!! You have guessed correctly!"

else
echo "Sorry, but that number is incorrect."
goto 1
endif

---After executing it lets me enter the first two numbers and then it returns the error "Event not found"

I found this in the Wikipedia article on the shell:

I'd read this:
http://www.grymoire.com/Unix/CshTop10.txt

Escape exclamation marks!!!

echo "Congratulations\!\! You have guessed correctly\!"

Wonderful..heh

What shell would you recommend doing this in? I dont think there are any requirements as to what shell to use. Are there any that might be better suited for my needs?

P.s. I appreciate the help

See what forum members think:

(and I should add, before someone reminds me, it's really bad practice to use goto's!)

haha i was about to say the exact same thing. it's been ages since i last saw a goto statement