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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Stoney L
    New Member
    • May 2022
    • 11

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

    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:
    Code:
    #include<bits/stdc++.h>
    using namespace std;
    double n,x,y,a;
    int main(){
    	cin>>n>>x>>y;
    	a=ceil(y/x);
    	if(y%x==0)cout<<n-y/x<<endl;
    	else cout<<n-a<<endl;
    	return 0;
    }
    (From the angry writer:Ahhh.... ..This DUMBDUDE code......)
    Last edited by zmbd; May 13 '22, 05:22 AM. Reason: [z{placed required [Code] tags - please use the [Code] formatting tool in the editor}]
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 655

    #2
    [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.

    Comment

    Working...