<分区>
这个程序应该从用户那里得到两个输入并显示答案。 这些是我得到的错误:
(15): error C2065: 'x' : undeclared identifier
(15): error C2065: 'y' : undeclared identifier
(16): error C2448: 'writeanswer' : function-style initializer appears to be a function definition
(30): error C3861: 'writeanswer': identifier not found
这是我的代码:
#include "stdafx.h"
#include <iostream>
using namespace std;
int Readnumber()
{
int num;
cin >> num;
return num;
}
void writeanswer(x, y) //THIS IS LINE 15
{ //THIS IS LINE 16
int a;
a = x + y;
cout << "This is the answer: " << a;
}
int main()
{
cout << "Please enter a number: ";
int x = Readnumber();
cout << "Please enter another number: ";
int y = Readnumber();
writeanswer(x, y); //THIS IS LINE 30
system("Pause");
return 0;
}
我认为第 30 行的错误是导致更多错误的主要问题。我试过谷歌,但似乎无法修复它。
编辑:我以为我已经试过了,我在这个问题上花了一整天!感谢所有的回答。