C++问题 初学者

来源:百度知道 编辑:UC知道 时间:2024/06/14 05:48:11
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
double x,y,r;
cout<<"输入两个直角边,一个斜边,空格隔开 by Txy"<<endl;
while (cin>>x>>y>>r)
{
if(x+y>r>x-y,x!=0,y!=0,r!=0)
{
cout<<"sin="<<y/r<<endl<<"cos="<<x/r<<endl
<<"tan="<<x/y<<endl<<"cot="<<y/x<<endl
<<"csc="<<r/y<<endl<<"sec="<<r/x<<endl;
}else{
cout<<"不符合构成三角形的条件 请检查后重新输入 by Txy"<<endl;
system("pause");
}
}
system("PAUSE");
return 0

可能是if(x+y>r>x-y,x!=0,y!=0,r!=0)语句的逻辑表达有问题,这里逗号语句有前后关系。d:\program files\microsoft visual studio\common\msdev98\bin\asdf.cpp(10) : warning C4804: '>' : unsafe use of type 'bool' in operation
改成if(x+y>r>x-y && x!=0 && y!=0 && r!=0)
在vc6上运行正常了。

if(x+y>r>x-y,x!=0,y!=0,r!=0)改成:
if(((x+y)>r)&&(r>(x-y))&&(x!=0)&&(y!=0)&&(r!=0))

在VC6.0中运行正确!

不会啊,我在DEVC++上调试没错啊