Guest User

Untitled

a guest
Oct 21st, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.         srand (time(NULL));
  10.  
  11.         int times = 1;
  12.  
  13.         if (argc == 2)
  14.         {
  15.                 stringstream ss(argv[1]);
  16.                 ss >> times;
  17.         }
  18.         else if (argc > 2)
  19.         {
  20.                 cout << "Usage: " << argv[0] << " <number of coins to flip>" << endl;
  21.                 return 1;
  22.         }
  23.         else if (argc == 1)
  24.                 cout << "Using 1 coin to flip!" << endl;
  25.  
  26.         for (int i = 0; i < times; i++)
  27.                 cout << ((rand()%RAND_MAX)%2 == 1 ? "Heads" : "Tails") << endl;
  28.  
  29.         return 0;
  30. }
Add Comment
Please, Sign In to add comment