c - 错误:二进制操作数无效

标签 c

我是初学者,我正在使用 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/

相关文章:

c - 如何区分可执行文件和自动运行文件

c - fstat() 返回 0,文件大小为 0,错误号为 11

c - C中的分而治之二分查找

char数组和char指针的比较

计算到特定时间的分钟数? (C)

c++ - Big Endian 字节与字符串作为字符串中的键 - 字符串数据库

c++ - 为什么我们可以在 C 中写越界?

c - 按字典顺序对整数数组进行排序

c - 关于 SNMP 中代理的 MIB 处理

c - 在C中逐位读取整个磁盘的内容