c++ - 无法调用函数

标签 c++ function arguments

我正在编写处理调用函数的代码。我大约进行了一半,当我尝试编译时出现错误“函数‘double()’的参数太多。” 这是我的代码。任何反馈都会有所帮助。

#include <iostream>
#include <cstdlib>

using namespace std;

void displayMenu();
double force();

int main(int argc, char** argv) 
{
    int menuOption;
    displayMenu();
    system("PAUSE");
    return 0;
}

void displayMenu(void)
{
    int menuOption;
    double weight;
    cout << "           Main Menu" << endl;
    cout << "Enter 1 for Force calculation with acceleration = 9.8m/s^2.\n";
    cout << "Enter 2 for Force calculation with user defined acceleration.\n";
    cout << "Enter 3 to quit the program.\n";
    cin >> menuOption;
        if(menuOption==1)
            cout << "Enter a mass.\n";
            cin >> weight;
            cout << force(weight);  
}

double force(double weight)
{
    double force, mass;
    force=(mass*9.8);
    return force;
}

最佳答案

double force(); 更改为 double force(double);

关于c++ - 无法调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33004898/

相关文章:

c++ - 对于 C++ Vector3 实用程序类实现,数组是否比结构和类快?

C++ 如何给抽象类中的成员变量一个默认值?

mysql - 插入功能不起作用[phpmyadmin,mysql]

c++ - 使用内置 Windows 方法获取文件夹内容

c++ - visual studio 2010 不更新 qrc 文件

javascript - 如何将循环中的本地数组连接到循环外的本地数组?

python - 我需要一个以正整数 (n) 开头并返回 2 的幂列表的函数,从 2 开始

python - 迭代函数参数并在 python 中保留排序顺序

c++ - 将数组作为函数中的引用参数传递

python - 如何解决Python错误 "not all arguments converted while string formatting"