Hi all,
I used a function called GetRandomVariable to return a double data type and here's its code:

double GetRandomNumber(void)
{
    // Zi = (AZi-1 + C)(mod m)
    // Zi = (5Zi-1 + 3)(mod 16)
    RandomVariableGenerator::Znode = (double)((5.0*RandomVariableGenerator::Znode + 3) % 16);
    return RandomVariableGenerator::Znode/16;
}
 static double Znode = 7.0;

but unfortunately i got the following error:

Error 1 error C2296: '%' : illegal, left operand has type 'double'

There is hope!

Use fmod to resolve the modulus between two doubles

#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main(){

    double x = fmod(4.5, 3.22);
    cout << x << endl; // 1 R 1.28, so 1.28 should print out
    cin.get();
    return 0;
}
Comments

Yes it works...i used the fmod function instead of implementing it by my self. thanks a lot Alex & William

This question has already been answered. Start a new discussion instead.