Thread: Pythagorean Help

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    7

    Pythagorean Help

    // n3n //
    Last edited by n3n; 09-25-2010 at 06:05 PM.

  2. #2
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    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 03:20 PM.
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    7
    Yes, I'm looking to print out 0, 1, 4, 9, 16

  4. #4
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    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.
    Explanation
    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
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    7
    thanks alot!
    I'm going to try this out right now and I'll let you know how it goes.

  6. #6
    Registered User
    Join Date
    Sep 2010
    Posts
    7
    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.

  7. #7
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    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.
    Code:
    double y;
    y = sqrt(z);
    floor(y);
    if((y*y) == z)
    Could you post your code this should work I'd like to see how you phrased it.
    Last edited by Lesshardtofind; 09-25-2010 at 04:52 PM.
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  8. #8
    Registered User
    Join Date
    Sep 2010
    Posts
    7
    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 06:05 PM. Reason: Don't want people copying

  9. #9
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    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 05:23 PM.
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  10. #10
    Registered User
    Join Date
    Sep 2010
    Posts
    7
    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 05:41 PM.

  11. #11
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    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 [email protected] I'm going to grab some supper then I'll check my email after hopefully I can help you find the problem.
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  12. #12
    Registered User
    Join Date
    Sep 2010
    Posts
    7
    ok I sent you an email with pictures showing the output

  13. #13
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    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.
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pythagorean triples
    By jack_carver in forum C Programming
    Replies: 4
    Last Post: 10-01-2009, 08:21 PM
  2. Pythagorean Numbers
    By NightLightSky in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2009, 09:34 PM
  3. Pythagorean Theorem Program Comment, criticize, or whatever
    By Sshakey6791 in forum C++ Programming
    Replies: 7
    Last Post: 02-13-2009, 02:48 AM
  4. Problem with Pythagorean triple etc.
    By -Prime- in forum C Programming
    Replies: 10
    Last Post: 10-14-2006, 01:50 AM
  5. Pythagorean Programming
    By mikeprogram in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2005, 01:29 PM