SilverhandX

coin.cpp

Mar 7th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include "coin.h"
  6. using namespace std;
  7.  
  8. Coin::Coin()
  9. {
  10.     unsigned seed = time(0);
  11.  
  12.     srand(seed);
  13.  
  14.     const int MIN = 1;
  15.     const int MAX = 2;
  16.  
  17.     int result = (rand() % (MAX - MIN + 1)) + MIN;
  18.  
  19.     if(result == 1)
  20.     {
  21.         sideUp = "heads";
  22.     }
  23.  
  24.     else if (result == 2)
  25.     {
  26.         sideUp = "tails";
  27.     }
  28. }
  29.  
  30. void Coin::toss()
  31. {
  32.     const int MIN = 1;
  33.     const int MAX = 2;
  34.  
  35.     int result = (rand() % (MAX - MIN + 1)) + MIN;
  36.  
  37.     if(result == 1)
  38.     {
  39.         sideUp = "heads";
  40.     }
  41.  
  42.     else if (result == 2)
  43.     {
  44.         sideUp = "tails";
  45.     }
  46. }
Add Comment
Please, Sign In to add comment