Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main() {
    double x, k, d;
    cin >> x >> k >> d;
    if(x == 0){
        cout << 0 << endl;
        return 0;
    }
    if(x>0){
        if(x-d*k>0){
            cout << x-d*k << endl;
            return 0;
        }else if(x-d*k==0){
            cout << 0 << endl;
            return 0;
        }else{
            if((k-x/d)%2.0 == 0) cout << x%d << endl;
            else cout << abs(x%d-d) << endl;
            return 0;
        }
    }else{
        if(x+d*k<0){
            cout << x+d*k << endl;
            return 0;
        }else if(x+d*k==0){
            cout << 0 << endl;
            return 0;
        }else{
            if((k-(-x)/d)%2.0 == 0) cout << (-x)%d << endl;
            else cout << abs((-x)%d-d) << endl;
            return 0;
        }
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:33:23: error: invalid operands of types 'double' and 'double' to binary 'operator%'
   33 |             if((k-x/d)%2.0 == 0) cout << x%d << endl;
      |                ~~~~~~~^~~~
      |                  |     |
      |                  |     double
      |                  double
a.cc:33:43: error: invalid operands of types 'double' and 'double' to binary 'operator%'
   33 |             if((k-x/d)%2.0 == 0) cout << x%d << endl;
      |                                          ~^~
      |                                          | |
      |                                          | double
      |                                          double
a.cc:34:31: error: invalid operands of types 'double' and 'double' to binary 'operator%'
   34 |             else cout << abs(x%d-d) << endl;
      |                              ~^~
      |                              | |
      |                              | double
      |                              double
a.cc:45:26: error: invalid operands of types 'double' and 'double' to binary 'operator%'
   45 |             if((k-(-x)/d)%2.0 == 0) cout << (-x)%d << endl;
      |                ~~~~~~~~~~^~~~
      |                  |        |
      |                  double   double
a.cc:45:49: error: invalid operands of types 'double' and 'double' to binary 'operator%'
   45 |             if((k-(-x)/d)%2.0 == 0) cout << (-x)%d << endl;
      |                                             ~~~~^~
      |                                              |   |
      |                                              |   double
      |                                              double
a.cc:46:34: error: invalid operands of types 'double' and 'double' to binary 'operator%'
   46 |             else cout << abs((-x)%d-d) << endl;
      |                              ~~~~^~
      |                               |   |
      |                               |   double
      |                               double