943,962 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 655
  • C++ RSS
Nov 22nd, 2008
0

Parsing error

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

C++ Syntax (Toggle Plain Text)
  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'
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Fouly is offline Offline
30 posts
since Oct 2007
Nov 22nd, 2008
0

Re: Parsing error

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.
Reputation Points: 1429
Solved Threads: 129
Posting Virtuoso
William Hemsworth is offline Offline
1,542 posts
since Mar 2008
Nov 22nd, 2008
1

Re: Parsing error

There is hope!

Use fmod to resolve the modulus between two doubles

c++ Syntax (Toggle Plain Text)
  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. }
Reputation Points: 392
Solved Threads: 108
Posting Shark
Alex Edwards is offline Offline
971 posts
since Jun 2008
Nov 22nd, 2008
0

Re: Parsing error

Yes it works...i used the fmod function instead of implementing it by my self. thanks a lot Alex & William
Reputation Points: 10
Solved Threads: 0
Light Poster
Fouly is offline Offline
30 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: converting bool[8] to char
Next Thread in C++ Forum Timeline: automating login to a server using c++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC