Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 real to int?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bgmrk




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: 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.
bgmrk




PostPosted: Sun Jan 29, 2006 4:53 pm   Post subject: (No subject)

thanx for the quick reply nd sry for not indenting

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




PostPosted: Sun Jan 29, 2006 5:08 pm   Post subject: (No subject)

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




PostPosted: Thu Feb 02, 2006 5:04 pm   Post subject: (No subject)

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




PostPosted: Thu Feb 02, 2006 5:10 pm   Post subject: (No subject)

it's for school...but i figured it out...thanx
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: