// n3n //
// n3n //
Last edited by n3n; 09-25-2010 at 07:05 PM.
I could be wrong but it looks like anything that has a square root that doesn't have to be rounded up or down to fit in a double will return true. When you say perfect square are you looking for a ordered list of whole numbers? 4, 9, 16, ect? You could try making Y an int so it is always rounded down after the sqrt then it should only be true when it is a whole number sqrt result... I may not forsee something though, just a guess.
Last edited by Lesshardtofind; 09-25-2010 at 04:20 PM.
Yes, I'm looking to print out 0, 1, 4, 9, 16
Is changing Y to a int rather than a double not an option? I just wrote a simple program to test the theory from numbers 0 - 100 and it gave me all the perfect squares by using y as a int so it automaticly rounded down.
Code:int y = sqrt(3) //result is 1.7321 //int Y will round this number to 1 (truncate) //then the test if((y*y) == z) //would be 1 * 1 = 3 .. false int y = sqrt(4) // (result is 2) //Since the number is even Y doesn't round //then the test if((y*y) == z) //would be 2* 2 = 4... true
I'm going to try this out right now and I'll let you know how it goes.
Yeah it's not working. It doesn't display anything.
I'm pretty sure my IF statement is wrong. Because I believe that it will miss out on some numbers.
strange I was able to show range 0 - 100, and I'm assuming negative numbers are not available squares because a negative and a negative is a positive square. So a negative number would require one side with a positive value and one side with a negative value. Can you possibly post your new code so I can check it? Oh are you using really large numbers? Possibly outside the numberic limits of a int. If that is the case then you can Make Y a double and use.
Could you post your code this should work I'd like to see how you phrased it.Code:double y; y = sqrt(z); floor(y); if((y*y) == z)
Last edited by Lesshardtofind; 09-25-2010 at 05:52 PM.
All I did was make y and int instead of a double but it seems like my print is whats the prblem if thats the case
I added my entire program a few minutes ago, but I don't want people to copy it just incase someone from my class sees it lol
Last edited by n3n; 09-25-2010 at 07:05 PM. Reason: Don't want people copying
Its fine I already copy and pasted it, and tested. My guess now is your problem isn't here, because I can print perfect squares so what I'm guessing is your assignment of the first list is what is not giving you the output you are expecting. Could you explain what your first list is supposed to do? So I can analyze your code vs your overall goal? Either PM me the complete code with added comments of explanation or just tell me what your first list is supposed to contain and each step you used to get there. You might stumble on the problem just by disecting it line by line with comments before you send it to me.. Sorry I'm not more help but I'm really not understanding why you are using the calculations you have for generating the first list.
Oh and while you are reading the code line by line test a "default" user input through all your values with a calculator and a peice of paper and see if the results are actually what you are expecting them to be.
Last edited by Lesshardtofind; 09-25-2010 at 06:23 PM.
Ok I was going to PM it but im not sure as to how I PM on this website?
I click your name and it brings me to a page saying "n3n, you do not have permission to access this page."
Last edited by n3n; 09-25-2010 at 06:41 PM.
Yea I noticed I can't post messages on yours as well. There must be a trial period for new users before you are allowed to recieve visitor messages and send PMs... email adress Haloismyvice@hotmail.com I'm going to grab some supper then I'll check my email after hopefully I can help you find the problem.
ok I sent you an email with pictures showing the output
I sent you a return email. I would ask that you don't remove all code from this post or else no one else can read it and learn from it. Honestly the fact that you showed the code here on your name shows you didn't copy from anyone else. Is your teacher actually against you posting any code in order to get help online?
If so your teacher should be aware the majority of users won't respond if you don't at least prove that you have written code before the question that was posed.