为什么在终端中出现cmath错误?

时间:2018-09-28 23:01:49

标签: c++ cmath

我无法在终端中编译代码,尤其是针对cmath的错误。

这是错误代码。

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)

当我在cpp.sh中运行代码时,它运行良好,但是编译后出现错误。

这是我的代码

#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);
    }
}

当然,由于这是一项家庭作业,因此缺少一些代码,但是我认为这应该有所帮助。

谢谢。

0 个答案:

没有答案