我正在尝试创建一个函数,该函数返回我将传递给它的整数的两倍。我的代码收到以下错误消息:
‘int x’ 的声明遮蔽了参数 int x; “
这是我的代码:
#include <iostream>
int doublenumber();
using namespace std;
int doublenumber(int x)// <-- this is the function which returns double the value .
{
int x;
return 2 * x;
cout << endl;
}
int main()
{
int a;
cout << "Enter the number that you want to double it : " << endl;
cin >> a;
doublenumber(a);
return 0;
}
原文由 grandx 发布,翻译遵循 CC BY-SA 4.0 许可协议
我这样做是因为您的建议很有帮助,这是最终结果: