+ 2

Error

double x=5,y=2; Int result; result=x%y; cout<< result; Why it gives error.. please explain

18th Feb 2020, 1:40 PM
Avinash
Avinash - avatar
6 odpowiedzi
+ 6
You can use % only for int datatype for double use fmod(x,y) function from <cmath> change result=fmod(x,y)
18th Feb 2020, 1:51 PM
Nandan
Nandan - avatar
+ 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. 
18th Feb 2020, 2:06 PM
BroFar
BroFar - avatar
+ 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.
18th Feb 2020, 5:44 PM
BroFar
BroFar - avatar
+ 2
lower case int result; and you cannot apply % operaror to double. Edit: % is the modulus operator ie returns the reminder in integer divison
18th Feb 2020, 1:42 PM
Mihai Apostol
Mihai Apostol - avatar
+ 2
That was not the problem of lower case. It says invalid operands of types 'double' and 'double' to binary 'operator%'
18th Feb 2020, 1:45 PM
Avinash
Avinash - avatar
+ 1
BroFar I just wanted to know why we can't use double.
18th Feb 2020, 3:15 PM
Avinash
Avinash - avatar