Computer Science Canada

real to int?

Author:  bgmrk [ Sun Jan 29, 2006 4:44 pm ]
Post subject:  real to int?

i'm trying to make a program that will recognize whether a number is a perfect square (8 is a perfect square of 64) or not i'm a little confused...i'm trying to use the round command to make it aout 100 times easier but its not going to well

this is what i have: Code:
code:

var x, y : real
for i : 40..100
y := i**0.5
if y*y = i then
put i
end if
end for


this gives all the numbers that aren't perfect squares

this is what i want
code:

var x, y : real
for i : 40..100
y := i**0.5
round (y)
if y*y = i then
put i
end if
end for

how do i fix this error so it actualy works

Author:  Delos [ Sun Jan 29, 2006 4:49 pm ]
Post subject:  Re: real to int?

Please indent.

bgmrk wrote:

code:

var x, y : real
for i : 40..100
   y := i**0.5
   % Takes sqrt.
   if y*y = i then
   % checks if square is i
      put i
   end if
end for



That part makes no sense. Basically, it's:
math wrote:

(sqrt(x))^2 = x


Ergo, all values will return.

What you'll want to do (if I understand your intent correctly) is check if the sqrt() of a given number is a whole number. If it is, then woo-hoo, it's a perfect square.
There are probably more mathematically correct ways of doing it, of course.

Author:  bgmrk [ Sun Jan 29, 2006 4:53 pm ]
Post subject: 

thanx for the quick reply nd sry for not indenting

where would i put that line because i am still ver confused

Author:  bgmrk [ Sun Jan 29, 2006 5:08 pm ]
Post subject: 

ok ok i got it...thanx..so much this was my last one to do..u r a god sent:)SmileSmile

Author:  redrenagade [ Thu Feb 02, 2006 5:04 pm ]
Post subject: 

Just what do you plan to use that for anyway? Just curious.

Author:  bgmrk [ Thu Feb 02, 2006 5:10 pm ]
Post subject: 

it's for school...but i figured it out...thanx


: