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'

double doesn't support the Modulus operator, you will have to implement it yourself if you want to do this.

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;
}
commented: ahh x) +5

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.