Computer Science Canada

No error message, and code does not fully compelet and ends

Author:  aznrex [ Thu Nov 17, 2005 6:06 pm ]
Post subject:  No error message, and code does not fully compelet and ends

code:
var num : int
var num2 : real
put "This program will check and see what is the maximum length of the"
put "square you can make with the number of squares you have"
put "(assuming they are all equal)."
put " "

put "How many squares do you have?"
get num

num2 := num**(1/2)

if (num2/num = 1/num2) then
put "it is square with ",num2," as the number of sides."

elsif (num2 = -1111) then
put "it is not"

end if


sry if it is a nooby question but i just started with turing. Can someone please help me see what is wrong with it?

Author:  Flikerator [ Thu Nov 17, 2005 6:23 pm ]
Post subject: 

What is the point of the program? It doesnt work because there is only a slight chance that either one of those could be true. I entered a bunch and the only one that worked was 10 (Which was very close to pi I might add).

Author:  aznrex [ Thu Nov 17, 2005 7:45 pm ]
Post subject: 

i am trying to write a program so that when given a number repersenting the number of equally shaped squares, can make a largest square possible with x amount of left over squares.
i am repersenting "num2" as the root of "num" so that "num2"/"num" will equal to 1/num2 if the number given was a a root with tn (term n) (also as n^n) ie t1 = 1^1 and t5= t^5.
that equation will only come true if the given num have a perfect square (like 4,9,16)

Author:  MysticVegeta [ Thu Nov 17, 2005 8:15 pm ]
Post subject: 

Let me guess. Pascal Contest. Problem #21. Part C? Am I right?

Author:  aznrex [ Thu Nov 17, 2005 8:44 pm ]
Post subject: 

No its not from pascal

but here is my revised code
code:

var iNum, cNum   : int
var rNum    : real

put "This program will check and see what is the maximum length of the"
put "square you can make with the number of squares you have"
put "(assuming they are all equal)."
put " "

put "How many squares do you have?"
get iNum

rNum := sqrt (iNum)
cNum := ceil (rNum : real) : int

put cNum,"this is the maximum length of the square with ",iNum," squares. There will be ",iNum - cNum**2," of squares left."


for some odd reason my ceil doesnt work, can someone please tell me why?

Author:  MysticVegeta [ Thu Nov 17, 2005 10:44 pm ]
Post subject: 

You need to do this->

Instead of putting
code:
cNum := ceil(r : real) : int


The r : real and : int are the parameters of the functions and the return values of that functions.

It means that in order to call that you need to pass that type of variable in that function.

so try this

code:
cNum := ceil(rNum)

Author:  aznrex [ Thu Nov 17, 2005 11:38 pm ]
Post subject: 

thanks alot,
works now, the explanation that came with turing sucks =P
the explanation u gave me made a heck lot more sense


: