0

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'

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Fouly
Featured Replies
  • There is hope! Use fmod to resolve the modulus between two doubles [code=c++] #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; } [/code] Read More

1

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
0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.