samedi 20 juillet 2019

How to use Modulus Operator with other data types?

i am trying to use Modulus Operator with float. can anyone tell me how can use Modulus Operator with float or double data type.

#include <iostream>
using namespace std;

int main()
{  
    float x = 100.23;
    cout<<"yes "<<x%2<<endl;
    return 0;
}

I am getting this error

main.cpp: In function ‘int main()’:
main.cpp:8:23: error: invalid operands of types ‘float’ and ‘float’ to binary ‘operator%’
    cout<<"yes "<<x%y<<endl;

Aucun commentaire:

Enregistrer un commentaire