调用时出现 C++ 编译器错误

标签 c++ compiler-errors

在我的计算机科学课上,我们正在制作一个程序,要求测量 4 个等腰梯形的高度、底部和顶部,计算周长并确定哪个具有最大周长。我的程序还没有完成,但我收到错误消息,指出没有匹配的函数可以调用 askInputcalcPerimeterfindMax .这是上下文的代码(抱歉,如果答案很明显,或者我的代码很草率,这是我参加的第一门编程课)。

#include <iostream>
#include <string>

using namespace std;

void intro();
void askInput();
double calcPerimeter();
double findMax();
double highest;

int main()
{
    intro();

    double t1, b1, h1, p1;  //Top, bottom, height, and perimiter of first trapezoid
    double t2, b2, h2, p2,
           t3, b3, h3, p3,
           t4, b4, h4, p4;  //other four trapezoids
    double max;             //largest perimeter

    askInput(t1, b1, h1, "first");
    askInput(t2, b2, h2, "second");
    askInput(t3, b3, h3, "third");
    askInput(t4, b4, h4, "fourth");

    p1 = calcPerimeter(t1, b1, h1);
    p2 = calcPerimeter(t2, b2, h2);
    p3 = calcPerimeter(t3, b3, h3);
    p4 = calcPerimeter(t4, b4, h4);

    max = findMax(p1, p2, p3, p4);

    cout << "Results" << endl;
    cout << "\tFirst: \tTop:" << t1 << "\tBottom: " << b1 << "\tHeight: " << h1 << "\tPerimeter: " << p1 << endl;
    cout << "\tSecond: \tTop:" << t2 << "\tBottom: " << b2 << "\tHeight: " << h2 << "\tPerimeter: " << p2 << endl;
    cout << "\tThird: \tTop:" << t3 << "\tBottom: " << b3 << "\tHeight: " << h3 << "\tPerimeter: " << p3 << endl;
    cout << "\tFourth: \tTop:" << t4 << "\tBottom: " << b4 << "\tHeight: " << h4 << "\tPerimeter: " << p4 << endl;
    cout << endl << "\tLargest Perimeter: " << highest << endl;


    system("pause");
    return 0;
}

void intro()
{
    cout << "Lab G: Trapezoid with largest perimeter" << endl;
    cout << "---------------------------------------" << endl; \
    cout << "This program will calculate the perimeter of four trapezoids." << endl;
    cout << "You will have to enter the top, bottom, and height of each trapezoid." << endl;
    cout << "The program will then find the trapezoid with the largest perimeter and output it." << endl;
}

void askInput(double &top, double &bottom, double &height, string whichT)
{
    cout << "Enter values for the " << whichT << " trapezoid." << endl;
    cout << "\tTop: ";
    cin >> top;
    cout << "\tBottom: ";
    cin >> bottom;
    cout << "\tHeight: ";
    cin >> height;
}

double calcPerimeter(double top, double bottom, double height)
{
    double answer;

    //some calculations

    return answer;
}

double findMax(double a, double b, double c, double d)
{
    double highest;
    highest = a;
    if (b > highest)
    {
        highest = b;
    }
    if (c > highest)
    {
        highest = c;
    }
    if (d > highest)
    {
        highest = d;
    }
    return highest;
}

最佳答案

声明中的函数签名必须与实现中的签名匹配。这意味着声明必须包含所有需要的函数参数类型。

void askInput(double &top, double &bottom, double &height, string whichT);

double calcPerimeter(double top, double bottom, double height);

double findMax(double a, double b, double c, double d);

关于调用时出现 C++ 编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32900903/

相关文章:

c++ - 在 C++ 中的单独文件中拥有命名空间的正确方法是什么?

c++ - 加解密生成器项目

c++库引用编译器错误

javascript - 找不到 App.js 模块;无法解决,编译失败

flutter - 在空上调用了 '[]'方法。接收器: null Tried calling: [](0)

c++ - 类的预制实例

c++ - 让一个引用成员引用另一个成员是否合法?

c++ - C++ 枚举访问语义背后的基本原理

c++ - 是否可以将 std::chrono::duration 与 Rep 类型一起使用为 double?我尝试在 vs2012 中遇到编译器错误

python - python 上的 cprofile 编译错误