0

I'm having trouble compiling my code in terminal the error specifically to cmath.

Here is the error codes.

area_calculator.cpp:45: error: call of overloaded `pow(int&, int)' is ambiguous
/usr/include/bits/mathcalls.h:154: error: candidates are: double pow(double, double)
/usr/include/g++/cmath:512: error: long double std::pow(long double, int)
/usr/include/g++/cmath:508: error: float std::pow(float, int)
/usr/include/g++/cmath:504: error: double std::pow(double,int)
/usr/include/g++/cmath:495: error: long double std::pow(long double, long double)
/usr/include/g++/cmath:486: error: float std::pow(float,float)

When I run the code in cpp.sh it works well, but after compiling there is an error.

Here is my code

#include <iomanip>
#include <iostream>
#include <cmath>

int main() {

    int optionNumber;
    int radius;
    const double pi = 3.14159;
    double circleArea;

    int length, width;
    double rectangleArea;

    int base, height;
    double triangleArea;

    if (n == 1) {

        std::cout << std::fixed;
        std::cout << std::setprecision(2);
        circleArea = pi * pow(radius, 2);

    } else if (n == 2) {

        std::cout << std::fixed;
        std::cout << std::setprecision(2);
        rectangleArea = length * width;


    } else if (n == 3) {

        std::cout << std::fixed;
        std::cout << std::setprecision(2);
        triangleArea = (base * height * 0.5);
    }
}

Of course, there are some codes missing since this is a homework assignment, but I think this should help.

Thanks in advance.

Swordfish
  • 12,971
  • 3
  • 21
  • 43
Francis
  • 11
  • 1
  • 2
    It says that call to pow is ambiguous because there is no direct overload for (int,int). There's no reason to use pow for squaring, just write `radius*radius`. – Quimby Sep 28 '18 at 23:08
  • 1
    if you read the manual (google 'man pow') https://linux.die.net/man/3/pow you will see that there is no version of pow that takes 2 integers. The compiler can convert the int you gave to a double or a float but it doesnt know which conversion u want so it gives up (it doesnt know that both versions of pow will do the same thing) – pm100 Sep 28 '18 at 23:15
  • I suggest you just multiply the number by itself, and not use `pow` at all for this program. – PaulMcKenzie Sep 28 '18 at 23:36
  • @PaulMcKenzie I always suggest the same, but [compilers](https://godbolt.org/z/bgN7kR) can be really smart, nowadays. – Bob__ Sep 29 '18 at 00:00
  • Which version of gcc are you using? Can you compile with -std=c++11 at least? – Bob__ Sep 29 '18 at 00:25

0 Answers0