/* This program will accept the input of two
integers, m and n. If m is greater than n
they will be used to calculate a Pythagorean triple, by
the formulas: ^2 means squared
side1 = m^2 - n^2
side2 = 2 m n
hypotenuse = square root of (side1^2 + side2^2)
these three numbers will always be the 3 sides
of a right triangle
*/
#include <iostream>
#include <cmath>
usingnamespace std;
int main ()
{
int m, n;
int side1, side2;
int hypotenuse;
cout << "Enter m ";
cin >> m;
cout << "Enter n ";
cin >> m;
if (m > n)
{
side1 = int(pow(m,2)) - int(pow(n,2));
side2 = 3 * m * n;
hypotenuse = sqrt(pow(side1,2)) + sqrt(pow(side2,2));
}
else
{
side1 = 0;
side2 = 0;
hypotenuse = 0;
cout << "please enter m greater than n" << endl;
}
cout << "The two legs of the triangle are " << side1 << " and "
<< side2 << endl << "and the hypotenuse is "
<< hypotenuse << endl;
return 0;
}
The error is said to be on the line with the side1 = in the if statement. is it my typecasting?
You didn't give the error your compiler is reporting, but VC++2005 gives an 'ambiguous call' error when using pow.
See http://www.cplusplus.com/reference/clibrary/cmath/pow.html for the definition of pow.
The compiler will automatically change the result of pow() to int, but it cannot resolve pow(int,int) into any of the three overloaded functions.
The simplest fix I found was to change it to
side1 = pow(m,2.0) - pow(n,2.0);
as the compiler can cope with pow(int, double).
Note that you will get the same error on line 30, with the same fix.
You also want to change line 26 to
This is off topic, but you will get different values for side1 (in line 29) and hypotenuse (line 30) than you have specified in comment lines in top of code. It's not important, of course, if this is only for testing ...