新手c++错误问题,,,,

程序如下:#include<iostream.h>main(){charlife_insurance[1];charhealth[1];intage=50;health=... 程序如下:
#include <iostream.h>

main()
{
char life_insurance[1];
char health[1];
int age=50;
health='B';
if (age<=55 && health=='G')
life_insurance='Y';
if (age<=55 && health=='B')
life_insurance='N';
if (age>55)
life_insurance='N';
cout<<"life insurance issued:"<<life_insurance<<"\n";

}

错误如下:
F:\Microsoft Visual Studio\MyProjects\borland\11.cpp(9) : error C2440: '=' : cannot convert from 'const char' to 'char [1]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
F:\Microsoft Visual Studio\MyProjects\borland\11.cpp(10) : error C2446: '==' : no conversion from 'int' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
F:\Microsoft Visual Studio\MyProjects\borland\11.cpp(10) : error C2040: '==' : 'char [1]' differs in levels of indirection from 'int'
F:\Microsoft Visual Studio\MyProjects\borland\11.cpp(11) : error C2440: '=' : cannot convert from 'const char' to 'char [1]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
F:\Microsoft Visual Studio\MyProjects\borland\11.cpp(12) : error C2446: '==' : no conversion from 'int' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
F:\Microsoft Visual Studio\MyProjects\borland\11.cpp(12) : error C2040: '==' : 'char [1]' differs in levels of indirection from 'int'
F:\Microsoft Visual Studio\MyProjects\borland\11.cpp(13) : error C2440: '=' : cannot convert from 'const char' to 'char [1]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
F:\Microsoft Visual Studio\MyProjects\borland\11.cpp(15) : error C2440: '=' : cannot convert from 'const char' to 'char [1]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
F:\Microsoft Visual Studio\MyProjects\borland\11.cpp(18) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.

11.exe - 1 error(s), 0 warning(s)
有人知道是怎么改错吗,,我怎么也改不过来,
展开
 我来答
040816214
2007-04-24 · TA获得超过103个赞
知道答主
回答量:112
采纳率:0%
帮助的人:0
展开全部
主要是前面定义的问题,char life_insurance[1];
char health[1];
修改成char life_insurance;char health;就对了
main()前加个void
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
负家子弟
2007-04-24 · TA获得超过3567个赞
知道大有可为答主
回答量:1336
采纳率:0%
帮助的人:1585万
展开全部
#include <iostream.h>

main()
{
char life_insurance; //同下
char health; //health='B'如果你要这样赋值就不要定义成数组,若要定义成数组就health[0]='B'这样赋值。

int age=50;
health='B';
if (age<=55 && health=='G')
life_insurance='Y';
if (age<=55 && health=='B')
life_insurance='N';
if (age>55)
life_insurance='N';
cout<<"life insurance issued:"<<life_insurance<<"\n";

}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式