Advertisement
Sinux1

T6E2

Mar 15th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. // Functions have four parts: body, name, parameters, return type
  8. string flip_coin()
  9. {
  10.     int random_number = rand() % 2;
  11.     if(random_number == 0)
  12.     {
  13.         return "HEADS"; // stops flip_coin and sends HEADS to where we left off
  14.     }
  15.     else
  16.     {
  17.         return "TAILS"; // stops flip_coin and sends TAILS to where we left off
  18.     }
  19. }
  20.  
  21. int main ()
  22. {
  23.     int num_seconds = time(NULL);
  24.     srand(num_seconds);
  25.  
  26.     int num_flips;
  27.     cout << "User - how many coin flips do you want?" << endl;
  28.     cin >> num_flips;
  29.  
  30.     for (int x = 1; x <= num_flips; x++)
  31.     {
  32.         cout << flip_coin() << endl; // flip coing simplifies to HEADS or TAILS
  33.     }
  34.  
  35.  
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement