470,632 Members | 1,392 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,632 developers. It's quick & easy.

[Error] invalid operands of types 'double' and 'double' to binary 'operator%'

1 Bit
Hey, can you guys tell me how to get this correct?It says "[Error] invalid operands of types 'double' and 'double' to binary 'operator%' "But I don't know what the error is!Under this sentence is my code:
Expand|Select|Wrap|Line Numbers
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. double n,x,y,a;
  4. int main(){
  5.     cin>>n>>x>>y;
  6.     a=ceil(y/x);
  7.     if(y%x==0)cout<<n-y/x<<endl;
  8.     else cout<<n-a<<endl;
  9.     return 0;
  10. }
(From the angry writer:Ahhh......This DUMBDUDE code......)
2 Weeks Ago #1
1 5641
569 Expert 512MB
[Error] invalid operands of types 'double' and 'double' to binary 'operator%'
% works with integral operands.

Use fmod https://www.cplusplus.com/reference/cmath/fmod/

Also, decimal comparisons may not be accurate.
1 Week Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by muthu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.