函数调用中的参数太少

-4 c++ visual-c++

我想void getInput在主要范围内调用该函数。但是当我这样做时,它告诉我:

函数调用中的参数太少。

我该如何解决?

第一个void函数将打印练习。然后在下一个称为的void函数中调用它getInput。之后,我只想在main()函数中调用它。

#include <iostream>;
#include <string>;

using namespace std;

void Exercices()
{
    double speed;
    int minutes;

    cout << "walking: ";
    cin >> speed >> minutes;
    cout << "running: ";
    cin >> speed >> minutes;
    cout << "cycling: ";
    cin >> speed >> minutes;
}

void getInput(string username)
{
    double weight, goal;
    string walking, running, cycling;

    cout << "Please enter your name: ";
    cin >> username;
    cout << "Welcome " << username << ", please enter your weight(kg): ";
    cin >> weight;
    cout << username << ", please enter speed(km/h) and minutes spent in a week for the activities below." << endl;
    Exercices();
    cout << username << ", please enter your weekly calorie burn goal: ";
    cin >> goal;

}
int main()
{
//string user_info;
    getInput();

    Exercices();

    cout << endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Des*_*tor 5

如错误所示,

int main()
{
    string user_info;
    getInput(user_info);

    Exercices();

    cout << endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

您必须将a传递string给函数,getInput(string username)因为函数定义说它需要一个。希望您以后阅读并尝试理解错误消息,然后再进行其他操作