Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while running program with certain operator and operands in C

Tags:

c

output

operand

I was trying to run a program but it shows an error as:

Invalid binary operator float to int

When I tried making it float it says:

Invalid binary operator float to float

The problem is with % operator And its operands.

Please tell me what to do?

#include <stdio.h>
int main()
{
    float x,y;
    scanf("%f%f",&x,&y);
    float z=x%5.0f;
    if(x<=y && z==0)
        printf("%.2f",y-x-0.50);
    else if (x>y || z!=0)
            printf("%.2f",y);
    return 0;
 }
like image 825
Satyarth Agrahari Avatar asked Sep 18 '26 16:09

Satyarth Agrahari


1 Answers

Modulus % only makes sense with integers because it is defined as the remainder from integer division. You can't do integer division with floats.

like image 147
chicks Avatar answered Sep 20 '26 07:09

chicks