Parsing error

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2007
Posts: 30
Reputation: Fouly is an unknown quantity at this point 
Solved Threads: 0
Fouly Fouly is offline Offline
Light Poster

Parsing error

 
0
  #1
Nov 22nd, 2008
Hi all,
I used a function called GetRandomVariable to return a double data type and here's its code:

  1. double GetRandomNumber(void)
  2. {
  3. // Zi = (AZi-1 + C)(mod m)
  4. // Zi = (5Zi-1 + 3)(mod 16)
  5. RandomVariableGenerator::Znode = (double)((5.0*RandomVariableGenerator::Znode + 3) % 16);
  6. return RandomVariableGenerator::Znode/16;
  7. }
  8. static double Znode = 7.0;
but unfortunately i got the following error:

Error 1 error C2296: '%' : illegal, left operand has type 'double'
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,400
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 113
Sponsor
William Hemsworth William Hemsworth is offline Offline
Nearly a Posting Virtuoso

Re: Parsing error

 
0
  #2
Nov 22nd, 2008
double doesn't support the Modulus operator, you will have to implement it yourself if you want to do this.
Last edited by William Hemsworth; Nov 22nd, 2008 at 8:20 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: Parsing error

 
1
  #3
Nov 22nd, 2008
There is hope!

Use fmod to resolve the modulus between two doubles

  1.  
  2. #include <iostream>
  3.  
  4. using std::cin;
  5. using std::cout;
  6. using std::endl;
  7.  
  8. int main(){
  9.  
  10. double x = fmod(4.5, 3.22);
  11. cout << x << endl; // 1 R 1.28, so 1.28 should print out
  12. cin.get();
  13. return 0;
  14. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 30
Reputation: Fouly is an unknown quantity at this point 
Solved Threads: 0
Fouly Fouly is offline Offline
Light Poster

Re: Parsing error

 
0
  #4
Nov 22nd, 2008
Yes it works...i used the fmod function instead of implementing it by my self. thanks a lot Alex & William
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC