views:

59

answers:

3

Write Script to read a positive integer number then it computes the following sequence: If the number is even, halve it If it is odd multiply it by 3 and add1

You should repeat this process until the value is 1, printing out each value and how many of these operations you performed.

#! bin\csh

echo "please enter any integer number :) "

set count=0

set number=$<

while($number != 1)

   if($number % 2) then

       @ number = number * 3 + 1 

   else

       @ number = number / 2

   endif

   echo " $number "

   @ count = count ++

end

echo I performed these operations $count times

When I run the script I get the following error: @: Expression Syntax.

A: 

What about the unquoted echo in the last line??

M0E-lnx
no problem with iti used it in another script :)
sara
+1  A: 

I believe its $variable to obtain its value

$
    Obtains the value of the variable. 

@ var = $a + $x * $z

source http://www.eng.hawaii.edu/Tutor/csh.html

So that would be

@count = $count +1 

And the line

#!bin\csh 

makes me shiver

Tom
Agreed, I would think it'd be something like #!/bin/csh
M0E-lnx
yes, thanks aloti forget it
sara
A: 

i get correct solution :)

#! /bin/csh

echo "please enter any integer number :) "

set count=0

set inc=1

set number=$<

while($number != 1)

   if($number % 2) then

       @ number = $number * 3 + 1 

   else

       @ number = $number / 2

   endif

   @ count = $count + $inc

   echo " $number "


end

echo I performed these operations $count times
sara