Expression syntax

March 18, 2009 at 01:12:46
Specs: Windows XP
I have one more problem, this one is alsmost solved, but I am getting Expression syntax message and I cannot figure out what's wrong. This program will print all the odd numbers between 0 and the one the user enters, in cshell. I think my logic is either good or almost there, but i dont see the errors. I think it could be the spaces between characters, maybe? Thanks !

This is what I have:

#!/bin/csh
# Print out all the odd numbers between 1 and a number user specifies
# If user enters a negative number, print out an error message
echo "Enter your number: "
set number = $<
set x=1
while ($x <=$number)
echo $x
@x =$x + 2
end


See More: Expression syntax

Report •


#1
March 18, 2009 at 09:55:41
I am really not up on csh syntax, but I can tell you that the syntax for your while loop is incorrect. It should be something like:

while (...
do
....
...
done


Report •

#2
March 18, 2009 at 11:37:52
Thank you, I tried it but it doesn't work neither. I am totally out of ideas.

#!/bin/csh
# Print out all the odd numbers between 1 and a number user specifies
# If user enters a negative number, print out an error message

echo "Enter your number: "
set number = $<
set x=1
while($x <=$number)
do
echo $x
@x = $x + 2
done
end


Report •

#3
March 18, 2009 at 12:46:26
I have no idea what this is:

@x = $x + 2

But if you are trying to add 2 to x, this works:


#!/usr/bin/csh

x=1
((x=x+2))
echo "x is: $x" # value should be 3

This also works if you are trying to add 2 to x:


#!/usr/bin/csh

x=1
((x+=2))
echo "x is: $x" # value should be 3



Report •

Related Solutions


Ask Question