C++primer plus第六版课后编程题答案7.8b
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;
}

浙公网安备 33010602011771号