pow function problems

Hello, I am trying to code a program that uses Pythagoras's Theorem to calculate a missing side on a right angled triangle. When I try to use the pow() function, I keep getting this error log that leads me to the 'math' header file (which is most definitely not wrong). Any help will be appreciated. Thanks,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

double adj;
double opp;

double pythagorasao_function (double adj, double opp)
{
       return pow((adj * adj) + (opp * opp));
}

int main(){
                cout << "Insert your Opposite." << endl;
                cin >> opp;
                cout << "Insert your Adjacent." << endl;
                cin >> adj;
                {
                double hyp_answer;
                hyp_answer = pythagorasao_function (adj, opp);
                cout << "Your answer is " << hyp_answer << endl;
                }
         
system("pause");       
return 0;
}
pow() function from <cmath> gets two arguments: base and power. You might got confused it with sqrt() function, which calculates square root.

And there is double hypot(double, double) function. Guess what does it do?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
//#include <stdio.h>
//#include <math.h>
#include <cmath>

//using namespace std;

//double adj;
//double opp;

double pythagorasao_function( double adj, double opp )
{
    return std::sqrt( adj*adj + opp*opp ) ;
}

int main()
{
    std::cout << "Insert your Opposite." << '\n' ;
    double opp ;
    std::cin >> opp;

    std::cout << "Insert your Adjacent." << '\n' ;
    double adj ;
    std::cin >> adj;

    if( adj>=0.0 && opp>=0.0 )
    {
        const double hyp_answer = pythagorasao_function( adj, opp ) ;
        std::cout << "Your answer is " << hyp_answer << '\n' ;
    }

    //system("pause");
    //return 0;
}
Thanks, it works :) MiiNiPaa thank you for explaining the functions :D
Topic archived. No new replies allowed.