
新手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)
有人知道是怎么改错吗,,我怎么也改不过来, 展开
#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)
有人知道是怎么改错吗,,我怎么也改不过来, 展开
2个回答
展开全部
主要是前面定义的问题,char life_insurance[1];
char health[1];
修改成char life_insurance;char health;就对了
main()前加个void
char health[1];
修改成char life_insurance;char health;就对了
main()前加个void
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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";
}
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";
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询