Author |
Message |
Hoshi
|
Posted: Mon Dec 19, 2011 4:57 pm Post subject: Syntax Error Help! |
|
|
the for count command is not working. Turing says that the variable is not declared. Doesn't the count command not need to be declared ![Question Question](http://compsci.ca/v3/images/smiles/icon_question.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Mon Dec 19, 2011 5:09 pm Post subject: RE:Syntax Error Help! |
|
|
"for count" isn't a command.
"for i : 1..10" is though. |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
Hoshi
|
Posted: Mon Dec 19, 2011 5:28 pm Post subject: RE:Syntax Error Help! |
|
|
what is wrong with this
var depth :int
var sum :int
get depth
for num: 1 .. depth
sum:= depth-3+2/num
exit when sum=num
put sum-num
end for |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
Hoshi
|
Posted: Mon Dec 19, 2011 8:22 pm Post subject: RE:Syntax Error Help! |
|
|
for num it says assigned value is the wrong type. |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Mon Dec 19, 2011 8:39 pm Post subject: RE:Syntax Error Help! |
|
|
Integers don't like being divided. They love div though. |
|
|
|
|
![](images/spacer.gif) |
tg851
![](http://compsci.ca/v3/uploads/user_avatars/769939254ed665749ae13.jpg)
|
Posted: Wed Dec 21, 2011 11:57 am Post subject: RE:Syntax Error Help! |
|
|
div will divide integers.floor,ceil,and round will divide 2 numbers to produce an integer of the result depending on the command |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
chipanpriest
![](http://compsci.ca/v3/uploads/user_avatars/2500543034edeb81cb83e9.jpg)
|
Posted: Wed Dec 21, 2011 12:24 pm Post subject: RE:Syntax Error Help! |
|
|
its because you are trying to divide an integer, which you cannot do unless you round it. an integer is a whole number, thus if you are dividing 3 by 2, you will get a decimal, which is not an integer |
|
|
|
|
![](images/spacer.gif) |
Aange10
![](http://compsci.ca/v3/uploads/user_avatars/19166165534f400d42de502.png)
|
Posted: Wed Dec 21, 2011 12:29 pm Post subject: RE:Syntax Error Help! |
|
|
Which just means that you can't divide 3/2 and store it as an integer. 1.5 is not an integer. However, you may store that into a real.
Here is an example of Ceil,Dividing,Div, and floor.
Turing: |
% Diving
put 5 / 2 % = Outputs 2.5 REAL
put 10 / 2 % = Outputs 2 REAL
put 21 / 2 % = Outputs 10.5 REAL
% Div { Divides without computing Remainders }
put 5 div 2 % Outputs 2 INT
put 10 div 2 % Outputs 5 INT
put 21 div 2 % outputs 10 INT
% Round
put round (5 / 2) % Outputs 3 INT
put round (10 / 2) % Outputs 5 INT
put round (21 / 2) % Outputs 11 INT
% Ceil {Rounds UP Always}
put ceil (5 / 2) % Outputs 3 INT
put ceil (10 / 2) % Outputs 5 INT
put ceil (21 / 2) % Outputs 11 INT
% Floor {Rounds Down Always}
put floor (5 / 2) % Outputs 2 INT
put floor (10 / 2) % Outputs 5 INT
put floor (21 / 2) % Outputs 10 INT
|
|
|
|
|
|
![](images/spacer.gif) |
chipanpriest
![](http://compsci.ca/v3/uploads/user_avatars/2500543034edeb81cb83e9.jpg)
|
Posted: Wed Dec 21, 2011 12:35 pm Post subject: RE:Syntax Error Help! |
|
|
Yea what he said and actually i didnt know about the ceil and floor commands either so thanks for that :p |
|
|
|
|
![](images/spacer.gif) |
|