我想在主作用域中调用void getInput
函数。但是当我这样做时,它告诉我:
函数调用中的参数太少。
我该如何解决?
第一个void函数将打印练习。然后,在下一个称为getInput
的void函数中调用它。之后,我只想在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;
}
答案 0 :(得分:5)
如错误所示,
int main()
{
string user_info;
getInput(user_info);
Exercices();
cout << endl;
return 0;
}
您必须将string
传递给函数getInput(string username)
,因为函数定义说它需要一个。希望您以后阅读并尝试理解错误消息