Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<time.h>
  4.  
  5. int getPlayerBet(int SEK)
  6. {
  7. int bet;
  8.  
  9. printf("\nYou have %d SEK. 1 for double/0 for nothing", SEK);
  10. scanf("%d", &bet);
  11.  
  12. while (bet > 1 || bet < 0)
  13. {
  14. printf("You have %d SEK, You must enter a 1 for double or 0 for nothing:", SEK);
  15. scanf("%d", &bet);
  16. }
  17.  
  18. if (bet == 1)
  19. {
  20. bet = SEK;
  21. }
  22.  
  23. else
  24. {
  25. bet = 0;
  26. }
  27.  
  28. return bet;
  29. }
  30.  
  31. int getPlayerGuess()
  32. {
  33. int guess;
  34. printf("\nWhat do you want to bet on? 0 for heads, 1 for tails:");
  35. scanf("%d", &guess);
  36. while (guess > 1 || guess < 0)
  37. {
  38. printf("you must enter either 0 for heads or 1 for tails:");
  39. scanf("%d", &guess);
  40. }
  41. return guess;
  42. }
  43.  
  44. int tosscoin()
  45. {
  46. int tal;
  47. tal = rand() % 2;
  48. printf("\n Tossing coin...... \n");
  49. return tal;
  50. }
  51.  
  52. int main(void)
  53. {
  54. srand((unsigned)time(0));
  55. int SEK = 100;
  56. int ammount;
  57. int headortail;
  58. int number;
  59. int halfbet;
  60.  
  61. while (SEK > 0) {
  62. ammount = getPlayerBet(SEK);
  63. if (ammount == 0)
  64. {
  65. printf("You have chosen to close the program, you quit with %d SEK!", SEK);
  66.  
  67. return 0;
  68. }
  69. headortail = getPlayerGuess();
  70. number = tosscoin();
  71.  
  72.  
  73. if (number < 1)
  74. {
  75. printf("It is heads!");
  76. }
  77. else
  78. {
  79. printf("It is tail");
  80. }
  81.  
  82. if (headortail != number)
  83. {
  84. SEK = SEK - ammount;
  85. printf("\nSorry you lost %d SEK.", ammount);
  86. }
  87. else
  88. {
  89. halfbet = ammount / 2;
  90. SEK = SEK + ammount+halfbet;
  91. printf("\nCongratulations you won %d SEK\n", ammount+halfbet);
  92. }
  93. }
  94.  
  95. printf("\nGame Over! You have no more money!");
  96.  
  97. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement