Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. //
  2. // main.c
  3. // EA1.1
  4. //
  5. // Created by Vlasiov Prifti on 14/12/2018.
  6. // Copyright © 2018 Vlasiov Prifti. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. int getPlayerBet(int BetPlayed);
  13. int tossCoin();
  14. int getPlayerGuess();
  15. int CurrentAmountOfMoney = 100;
  16.  
  17.  
  18. int main()
  19. {
  20. int bet1, Bet=0;
  21.  
  22.  
  23.  
  24. while(CurrentAmountOfMoney > 0 )
  25. {
  26. printf("\nYou have %d SEK. How much do you want to bet?",CurrentAmountOfMoney);
  27. scanf("%d",&bet1);
  28. Bet = getPlayerBet(bet1);
  29.  
  30. if (Bet == 0)
  31. {
  32. break;
  33. }
  34.  
  35. if(getPlayerGuess() == tossCoin())
  36. {
  37. printf("You won %d\n", Bet);
  38. CurrentAmountOfMoney += Bet;
  39. }
  40. else {
  41. printf("You lost %d\n", Bet);
  42. CurrentAmountOfMoney -= Bet;
  43. }
  44.  
  45. }
  46. printf("Game over.");
  47.  
  48. }
  49.  
  50. int getPlayerBet(int BetPlayed)
  51. {
  52. if(BetPlayed !=0)
  53. {
  54. while(BetPlayed > CurrentAmountOfMoney || BetPlayed < 0)
  55. {
  56. printf("Bet again!\n");
  57.  
  58. scanf("%d", &BetPlayed);
  59. }
  60.  
  61. return BetPlayed;
  62. }
  63. printf("Game over. You have %d \n",CurrentAmountOfMoney);
  64. return 0;
  65. }
  66.  
  67.  
  68. int getPlayerGuess()
  69. {
  70.  
  71. int PlayerGuess;
  72. printf("What do you want to bet on? 1 for heads, 0 for tails:");
  73. scanf("%d",&PlayerGuess);
  74.  
  75. while(PlayerGuess != 1 && PlayerGuess != 0)
  76. {
  77. printf("Guess again:");
  78. scanf("%d", &PlayerGuess);
  79. }
  80.  
  81. if(PlayerGuess == 1)
  82. return 1;
  83. if (PlayerGuess == 0)
  84. return 0;
  85.  
  86. return PlayerGuess;
  87. }
  88.  
  89. int tossCoin()
  90. {
  91. printf("Tossing coin … ");
  92.  
  93. int tossing = rand()%2;
  94.  
  95. if(tossing ==1)
  96. {
  97. printf("it is heads\n");
  98. return 1;
  99.  
  100.  
  101. }
  102. else
  103. printf("it is tails\n");
  104. return 0;
  105.  
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement