Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Any help with this grade 11 program relating to Pythagorean Triplets?
Author Message
xanderman2113

Posted: Mon Nov 10, 2014 12:17 pm   Post subject: Any help with this grade 11 program relating to Pythagorean Triplets?

I am having some trouble wrapping my head around this question. We are asked to do full documentation beforehand, but sometimes coding first helps me. Any ideas are greatly appreciated.

We are using BlueJ 1.3.5

Thanks!

Three positive integers a, b, and c with a < b < c form a Pythagorean
triplet if a2 + b2 = c2. For example, 3, 4, and 5 form a Pythagorean
triplet since 32 + 42 = 52. Write a program that first prompts the
user for a positive integer and then finds and prints all Pythagorean
triplets whose largest member is less than or equal to that integer.

williamd

Posted: Mon Nov 10, 2014 12:47 pm   Post subject: RE:Any help with this grade 11 program relating to Pythagorean Triplets?

yes
Insectoid

Posted: Mon Nov 10, 2014 12:54 pm   Post subject: RE:Any help with this grade 11 program relating to Pythagorean Triplets?

Basically you're just tossing some equations into a nested for loop. Should look something like this:

 code: for (int c = ?; ??; ??) {     for (int b = ?; ??; ??){         for (int a = ?;??; ??){             //check if a, b, c satisfy requirements and print         }     } }

Replace the ??s with code that will makes each of a, b, c to run the appropriate number of times and throw and equations into the middle to check if that combination of a,b,c works. This can be done in a single if statement using the && (and) operator.
xanderman2113

Posted: Mon Nov 10, 2014 6:10 pm   Post subject: Re: RE:Any help with this grade 11 program relating to Pythagorean Triplets?

Insectoid @ Mon Nov 10, 2014 12:54 pm wrote:
Basically you're just tossing some equations into a nested for loop. Should look something like this:

 code: for (int c = ?; ??; ??) {     for (int b = ?; ??; ??){         for (int a = ?;??; ??){             //check if a, b, c satisfy requirements and print         }     } }

Replace the ??s with code that will makes each of a, b, c to run the appropriate number of times and throw and equations into the middle to check if that combination of a,b,c works. This can be done in a single if statement using the && (and) operator.

Thanks for the starting code, I think I know what I need to do now. I will get back to you. Thanks!
xanderman2113

Posted: Mon Nov 10, 2014 8:29 pm   Post subject: Re: Any help with this grade 11 program relating to Pythagorean Triplets?

Alright I got this pretty much down pat just one small error I can't seem to find. Here is a direct link to the picture: http://prntscr.com/555qkd
Thanks!
Tony

Posted: Mon Nov 10, 2014 9:20 pm   Post subject: RE:Any help with this grade 11 program relating to Pythagorean Triplets?

That's not a very good error message It should have told you that it has to do with = vs ==

P.S. your program's comments suggest that you are missing a part of the original requirement
Quote:

whose largest member is less than or equal to that integer
Tony's programming blog. DWITE - a programming contest.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 6 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: