Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.c
- // EA1.1
- //
- // Created by Vlasiov Prifti on 14/12/2018.
- // Copyright © 2018 Vlasiov Prifti. All rights reserved.
- //
- #include <stdio.h>
- #include <stdlib.h>
- int getPlayerBet(int BetPlayed);
- int tossCoin();
- int getPlayerGuess();
- int CurrentAmountOfMoney = 100;
- int main()
- {
- int bet1, Bet=0;
- while(CurrentAmountOfMoney > 0 )
- {
- printf("\nYou have %d SEK. How much do you want to bet?",CurrentAmountOfMoney);
- scanf("%d",&bet1);
- Bet = getPlayerBet(bet1);
- if (Bet == 0)
- {
- break;
- }
- if(getPlayerGuess() == tossCoin())
- {
- printf("You won %d\n", Bet);
- CurrentAmountOfMoney += Bet;
- }
- else {
- printf("You lost %d\n", Bet);
- CurrentAmountOfMoney -= Bet;
- }
- }
- printf("Game over.");
- }
- int getPlayerBet(int BetPlayed)
- {
- if(BetPlayed !=0)
- {
- while(BetPlayed > CurrentAmountOfMoney || BetPlayed < 0)
- {
- printf("Bet again!\n");
- scanf("%d", &BetPlayed);
- }
- return BetPlayed;
- }
- printf("Game over. You have %d \n",CurrentAmountOfMoney);
- return 0;
- }
- int getPlayerGuess()
- {
- int PlayerGuess;
- printf("What do you want to bet on? 1 for heads, 0 for tails:");
- scanf("%d",&PlayerGuess);
- while(PlayerGuess != 1 && PlayerGuess != 0)
- {
- printf("Guess again:");
- scanf("%d", &PlayerGuess);
- }
- if(PlayerGuess == 1)
- return 1;
- if (PlayerGuess == 0)
- return 0;
- return PlayerGuess;
- }
- int tossCoin()
- {
- printf("Tossing coin … ");
- int tossing = rand()%2;
- if(tossing ==1)
- {
- printf("it is heads\n");
- return 1;
- }
- else
- printf("it is tails\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement