No, use pow(base, exponent). |
Why? x
2 is the same as x*x, so unless the user types in some super huge number for a homework assignment, then there won't be any problems.
Although, I would tend to use
doubles instead of
ints for the lengths.
I will use pow in the GetDimensions() function. |
Why? Don't mix stuff up.
GetDimensions() should only get the actual lengths of the sides from the user. It shouldn't return something else, like the squared dimensions or the like.
Keep all the math in one spot: in IsRightTriangle().
Determine which side is longest. Hint: given three sides, just make sure the one you want to be the longest is the longest. That is, if you say that sideC should be the longest, then it should be larger than sideA and sideB. Then follow the instructions given you to make it easy:
1a. if sideC < sideA then swap the values of sideC and sideA
1b. if sideC < sideB then swap the values of sideC and sideB
2. multiply each side by itself: sideA *= sideA; ...
3. return the comparison sideC == sideA + sideB
Again, all this only belongs in the IsRightTriangle() function. Other parts of your code should not be involved in the calculation.
The bool is new to me so I'm not sure. |
You used it just fine on lines 38 through 47 of your first post.
The
type of a thing is important. Since
IsRightTriangle() returns a
bool, the following should also be
bools:
- The
YesOrNo variable (
bool YesOrNo;
)
- The argument to
DisplayResults() (
void DisplayResults(bool results)
)
Hope this helps.