您的位置:首页 > 编程语言 > C语言/C++

C++primer plus第六版课后编程题答案7.8b

2014-04-10 10:47 357 查看
7.8b

vs2010不知道搞毛,居然爆了一推出错。

但是在Dev c++运行完成没问题,暂时还不知道为什么。

已经搞清楚了错误所在。

原因是:std名称空间已经有了exp这个关键词的存在!

将exp改为Exp或者

using namespace std改为

using std::cout;

using std::cin;

#include <iostream>
using namespace std;
const int Seasons=4;
const char *season[Seasons]={"Spring","Summer","Fall","Winter"};
struct exp
{
double ex[Seasons];
};
void fill(exp &ex);
void show(const exp &ex);
int main()
{
exp ex;
fill(ex);
show(ex);
cin.get();
system("pause");
return 0;
}
void fill(exp &ex)
{
for(int i=0;i<Seasons;i++)
{
cout<<"\nEnter  "<<*(season+i)<<" expenses:";
cin>>ex.ex[i];
}
cout<<"Enter end!";

}
void show(const exp &ex)
{
cout<<"\nshow start!"<<endl;
for(int i=0;i<Seasons;i++)
{
cout<<"The "<<*(season+i)<<" expenses is "<<ex.ex[i]<<endl;

}
cout<<"show endl"<<endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: