做C++的一道题总报错

来源:百度知道 编辑:UC知道 时间:2024/06/04 20:44:50
#include<iostream.h>
void main()
{
int i(1),sun(0);
while(i<=10)
{
sum+=i;
i++;
}
cout<<"sum="<<sum
<<endl;
}

H:\c++test\plus\test.cpp(7) : error C2065: 'sum' : undeclared identifier

我改写成sum=sum+i++; 也是错
奇怪了,我可是按照老师的步骤写的,内容都一样的,到底错在哪呢?

定义的sun用成了sum

原意应该是定义sum的,错写成sun了才对。

H:\c++test\plus\test.cpp(7) : error C2065: 'sum' : undeclared identifier

这句话的意思是:“sum” 未定义的标识符

定义的是sun啊。