这C++程序为什么运行不了?错误显示:错误 1 error C3861: “getresult”: 找不到标识符
#include<iostream>usingnamespacestd;intage;intmain(){cout<<"Pleaseenteryourage!"<<end...
#include <iostream>
using namespace std;
int age;
int main(){
cout<<"Please enter your age!"<<endl;
cin>>age;
getresult();
system("pause");
return 0;
}
void getresult(){
if(age>30){
cout<<"You are old!"<<endl;
}
else{
cout<<"Your are young!"<<endl;
}
} 展开
using namespace std;
int age;
int main(){
cout<<"Please enter your age!"<<endl;
cin>>age;
getresult();
system("pause");
return 0;
}
void getresult(){
if(age>30){
cout<<"You are old!"<<endl;
}
else{
cout<<"Your are young!"<<endl;
}
} 展开
1个回答
展开全部
把getresult函数声明放到main()之前,让编译器知道有getresult()这个函数。
#include <iostream>
using namespace std;
void getresult();
int age;
int main(){
cout<<"Please enter your age!"<<endl;
cin>>age;
getresult();
system("pause");
return 0;
}
void getresult()
{
if(age>30){
cout<<"You are old!"<<endl;
}
else{
cout<<"Your are young!"<<endl;
}
}
#include <iostream>
using namespace std;
void getresult();
int age;
int main(){
cout<<"Please enter your age!"<<endl;
cin>>age;
getresult();
system("pause");
return 0;
}
void getresult()
{
if(age>30){
cout<<"You are old!"<<endl;
}
else{
cout<<"Your are young!"<<endl;
}
}
参考资料: C语言手册
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询