C++ 问题 unsafe use of type 'bool' in operation

作者&投稿:郜油 (若有异议请与网页底部的电邮联系)
c++ unsafe use of type 'bool' in operation~

else if(85<=score<=100) cout<<"very good"<<endl;
else if(60<=score<85) cout<<"good"<<endl;
else if(0<=score<60) cout<<"not good"<<endl;
问题出在这里
C++中不允许这样的写法,你要想表示85=85&&score<=100

这是C++里的吧,Ansi C里面没有bool,你应该是使用的C++编译器编译C程序
这句话的意思:对bool类型使用“<”操作符是不安全的……
不过只是waring,不影响编译通过的。

这里判断有误。
if (y==Y||y==y)
修改为: if (y=='Y' ||y== 'y')

修改后的代码:
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{ double n=2.54e-2;
const int m=12;
const double x=2.2;
int a,b,c,e;
double d,f,BMI;
char y;
cout<<"请输入身高(英尺)";
cin>>a;
cout<<"请输入身高(英寸)";
cin>>b;
c=a*m+b;
d=c*n;
cout<<"你的身高是 "<<setprecision(2)<<setiosflags(ios::fixed)<<d<<"米"<<endl;
cout<<"请输入体重(磅)";
cin>>e;
f=e/x;
cout<<"你的体重是"<<f+f<<"斤"<<endl;
BMI=f/(d*d);
cout<<"BMI= "<<BMI<<endl;
cout<<"你是男的么(Y/N)?"<<endl;
cin>>y;
y=y;
if (y=='Y' ||y== 'y')
{if (BMI<20) cout<<"过轻,得多吃点!\n";
else if (20<=BMI<25) cout<<"适中,继续保持!\n";
else if (25<=BMI<30) cout<<"过重,该运动啦!\n";
else if (30<=BMI<35) cout<<"肥胖,不能吃啦!\n";
else if (35<=BMI) cout<<"非常肥胖,要进医院了!\n";
}
else
{if (BMI<19) cout<<"过轻,得多吃点!\n";
else if (19<=BMI<24) cout<<"适中,继续保持!\n";
else if (24<=BMI<29) cout<<"过重,该运动啦!\n";
else if (29<=BMI<34) cout<<"肥胖,不能吃啦!\n";
else if (34<=BMI) cout<<"非常肥胖,要进医院了!\n";
}
return 0;
}

#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{ double n=2.54e-2;
const int m=12;
const double x=2.2;
int a,b,c,e;
double d,f,BMI;
char y;
cout<<"请输入身高(英尺)";
cin>>a;
cout<<"请输入身高(英寸)";
cin>>b;
c=a*m+b;
d=c*n;
cout<<"你的身高是 "<<setprecision(2)<<setiosflags(ios::fixed)<<d<<"米"<<endl;
cout<<"请输入体重(磅)";
cin>>e;
f=e/x;
cout<<"你的体重是"<<f+f<<"斤"<<endl;
BMI=f/(d*d);
cout<<"BMI= "<<BMI<<endl;
cout<<"你是男的么(Y/N)?"<<endl;
cin>>y;
y=y;
if (y=='Y'||y=='y')
{if (BMI<20) cout<<"过轻,得多吃点!\n";
else if (20<=BMI&&BMI<25) cout<<"适中,继续保持!\n";
else if (25<=BMI&&BMI<30) cout<<"过重,该运动啦!\n";
else if (30<=BMI&&BMI<35) cout<<"肥胖,不能吃啦!\n";
else if (35<=BMI&&BMI) cout<<"非常肥胖,要进医院了!\n";
}
else
{if (BMI<19) cout<<"过轻,得多吃点!\n";
else if (19<=BMI&&BMI<24) cout<<"适中,继续保持!\n";
else if (24<=BMI&&BMI<29) cout<<"过重,该运动啦!\n";
else if (29<=BMI&&BMI<34) cout<<"肥胖,不能吃啦!\n";
else if (34<=BMI) cout<<"非常肥胖,要进医院了!\n";
}
return 0;
}
现在好了,对于联合判断19<=BMI<24可能编译器判断有些问题,使用&&就好了


叶城县17362651298: C语言这错误什么意思'%' : unsafe use of type 'bool' in operation -
浦丹丽科: if(!j%2) if(!(j%2))

叶城县17362651298: C++ 问题 unsafe use of type 'bool' in operation -
浦丹丽科: 这里判断有误. if (y==Y||y==y) 修改为: if (y=='Y' ||y== 'y') 修改后的代码:#include <iostream>#include <iomanip> using namespace std; int main () { double n=2.54e-2; const int m=12; const double x=2.2; int a,b,c,e; double d,f,BMI; char y; cout<<"...

叶城县17362651298: 初学C++,请教一个简单的问题 -
浦丹丽科: #include<iostream> using namespace std; int main() { int v1=0,v2=0; cout<<"Please enter the small number and the large number:"<<endl; cin>>v1>>v2; while(v1<=v2){ cout<<v1<<endl; v1+=1; } return 0; } 代码如上,养成用在mian()函数前...

叶城县17362651298: 帮个忙吧各位C大虾!c语言中:warning C4804: '<' : unsafe use of type 'bool' in operation -
浦丹丽科: 这是C++里的吧,Ansi C里面没有bool,你应该是使用的C++编译器编译C程序 这句话的意思:对bool类型使用“不过只是waring,不影响编译通过的.

叶城县17362651298: C++问题 初学者 -
浦丹丽科: 可能是if(x+y>r>x-y,x!=0,y!=0,r!=0)语句的逻辑表达有问题,这里逗号语句有前后关系.d:\program files\microsoft visual studio\common\msdev98\bin\asdf.cpp(10) : w...

叶城县17362651298: vc6.0 warning C4804: '>' : unsafe use of type 'bool' in operation -
浦丹丽科: 代码没问题,我在VC6下编译通过,不过你的代码是取3个数的最小值,要取最大值,max>b和max>c 应该改为 max<b和max<c.编译不过是你的编译环境有问题,去Tools->Options->Directories目录看看你的设置对不对.

叶城县17362651298: "unsafe use of type 'bool' in operation" 我的程序是#includeusing namespace std;void main(){char c1='a',c2='b',c3='c';int i1=10,i2=20,i3=30;double d1=0.1,d... -
浦丹丽科:[答案] 警告:操作中"布尔"型数据不安全的使用. x=i1>i2>i3

叶城县17362651298: 电脑总是出现这个提示好像是C++的问题 -
浦丹丽科: 这是提示有某一个文件在系统启动时损坏或运行不了,却又不影响系统的开启与运行,但会对某种应用程序不能运行或某一功能执行不了,建议对操作系统进行修复,看看能不能解决问题,实在不行重装系统.

叶城县17362651298: c语言中:warning C4804: '<' : unsafe use of type 'bool' in operation -
浦丹丽科: bool变量用来比较了

叶城县17362651298: 如何使用C#中的unsafe模式 -
浦丹丽科: 把非安全代码放在unsafe{ }中...通过VS自带的命令行工具编译...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网