
-----------------------------------
bgmrk
Sun Jan 29, 2006 4:44 pm

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: 

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 

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

-----------------------------------
Delos
Sun Jan 29, 2006 4:49 pm

Re: real to int?
-----------------------------------
Please indent.



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:

(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.

-----------------------------------
bgmrk
Sun Jan 29, 2006 4:53 pm


-----------------------------------
thanx for the quick reply nd sry for not indenting

where would i put that line because i am still ver confused

-----------------------------------
bgmrk
Sun Jan 29, 2006 5:08 pm


-----------------------------------
ok ok i got it...thanx..so much this was my last one to do..u r a god sent:):):)

-----------------------------------
redrenagade
Thu Feb 02, 2006 5:04 pm


-----------------------------------
Just what do you plan to use that for anyway? Just curious.

-----------------------------------
bgmrk
Thu Feb 02, 2006 5:10 pm


-----------------------------------
it's for school...but i figured it out...thanx
