Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<time.h>
- int getPlayerBet(int SEK)
- {
- int bet;
- printf("\nYou have %d SEK. 1 for double/0 for nothing", SEK);
- scanf("%d", &bet);
- while (bet > 1 || bet < 0)
- {
- printf("You have %d SEK, You must enter a 1 for double or 0 for nothing:", SEK);
- scanf("%d", &bet);
- }
- if (bet == 1)
- {
- bet = SEK;
- }
- else
- {
- bet = 0;
- }
- return bet;
- }
- int getPlayerGuess()
- {
- int guess;
- printf("\nWhat do you want to bet on? 0 for heads, 1 for tails:");
- scanf("%d", &guess);
- while (guess > 1 || guess < 0)
- {
- printf("you must enter either 0 for heads or 1 for tails:");
- scanf("%d", &guess);
- }
- return guess;
- }
- int tosscoin()
- {
- int tal;
- tal = rand() % 2;
- printf("\n Tossing coin...... \n");
- return tal;
- }
- int main(void)
- {
- srand((unsigned)time(0));
- int SEK = 100;
- int ammount;
- int headortail;
- int number;
- int halfbet;
- while (SEK > 0) {
- ammount = getPlayerBet(SEK);
- if (ammount == 0)
- {
- printf("You have chosen to close the program, you quit with %d SEK!", SEK);
- return 0;
- }
- headortail = getPlayerGuess();
- number = tosscoin();
- if (number < 1)
- {
- printf("It is heads!");
- }
- else
- {
- printf("It is tail");
- }
- if (headortail != number)
- {
- SEK = SEK - ammount;
- printf("\nSorry you lost %d SEK.", ammount);
- }
- else
- {
- halfbet = ammount / 2;
- SEK = SEK + ammount+halfbet;
- printf("\nCongratulations you won %d SEK\n", ammount+halfbet);
- }
- }
- printf("\nGame Over! You have no more money!");
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement