我是初学者,我正在使用 dev c++ 。我正在尝试编写一个函数来确定它位于哪个象限。它相当简单,但我收到错误 [Error] invalid operands to binary << (have 'float' and 'int')
#include <stdio.h>
int quadrant (float i, float j);
int main()
{
float a,b;
int c;
scanf ("%f,%f",&a,&b);
c=quadrant(a,b);
printf("the given point lies in %d quadrant",c);
return 0;
}
int quadrant (float i, float j)
{
if (i>>0 && j>>0)
return 1;
else if (i>>0 && j<<0)
return 4;
else if (i<<0 && j>>0)
return 2;
else if (i<<0 && j<<0)
return 3;
else
return 0;
}
是因为 float 不能与二进制操作数一起使用吗? 我用int替换了float,所有的float。这次,当我编译时,我收到错误 ID:return 1 status。 我的代码有什么问题吗?
最佳答案
您对比较运算符感到困惑 < , > , <= , >= , !=
和按位运算符 << >>
。将按位运算符替换为相应的比较运算符。
int quadrant (float i, float j)
{
if (i>0 && j>0)
return 1;
else if (i>0 && j<0)
return 4;
else if (i<0 && j>0)
return 2;
else if (i<0 && j<0)
return 3;
else
return 0;
}
关于c - 错误:二进制操作数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36324980/