Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int coinToss(void)
  8. {
  9. int coinFlip;
  10. coinFlip = rand() % 2;
  11. return coinFlip;
  12.  
  13. }
  14.  
  15. int main()
  16. {
  17. int howManyTimes = 0;
  18. int coinFlip = 0;
  19. string headTail = "";
  20.  
  21. cout << "How many times do you want to toss the coin? ";
  22. cin >> howManyTimes;
  23.  
  24. srand((time(0)));
  25.  
  26.  
  27. for (int i = 1; i <= howManyTimes; i++)
  28. {
  29. coinFlip = coinToss();
  30. if (coinFlip == 1)
  31. headTail = "heads";
  32. else
  33. headTail = "tails";
  34.  
  35. cout << headTail << endl;
  36.  
  37. }
  38. return 0;
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement