+ 2
Error
double x=5,y=2; Int result; result=x%y; cout<< result; Why it gives error.. please explain
6 Respuestas
+ 6
You can use % only for int datatype
for double use fmod(x,y) function from <cmath>
change result=fmod(x,y)
+ 3
Raj Vinus why are you using double on x and y just use int and change Int to int on result
https://code.sololearn.com/cIN6wnynW4bc/?ref=app
https://code.sololearn.com/cjVbLd6t0MBb/?ref=app
The double is a fundamental data type built into the compiler and used to define numeric variables holding numbers with decimal points.
+ 3
The double is a fundamental data type built into the compiler and used to define numeric variables holding numbers with decimal points.
Neither x nor y in your code reflect a decimal being used nor does result.
+ 2
lower case int result;
and you cannot apply % operaror to double.
Edit: % is the modulus operator ie returns the reminder in integer divison
+ 2
That was not the problem of lower case. It says invalid operands of types 'double' and 'double' to binary 'operator%'
+ 1
BroFar I just wanted to know why we can't use double.