1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void play_craps();
int die_1,die_2,die_3,die_4,roll,roll_2;
int bet=0;
int chipBalance=100;
int play;
int gamesWon=0;
int gamesLost=0;
char answer,junk;
int main(void)
{
char answer,junk;
do
{
printf("\n\n\n");
printf("Would you like to play craps?\n\n");
answer=getchar();
junk=getchar();
if(answer=='y' || answer=='Y')
{
play_craps();
play++;
}
}while(answer=='y' || answer=='Y');
play_craps();
}
void play_craps()
{
play=gamesWon+gamesLost;
srand((unsigned)time(NULL));
printf("Number of chips: %d\n", chipBalance);
printf("\nHow much would you like to bet?\n");
scanf("%d", &bet);
die_1= 1+ rand() %6;
die_2= 1+ rand() %6;
roll=die_1 + die_2;
printf("\nYou rolled %d + %d = %d\n",die_1,die_2,roll);
if( roll==4 || roll==5 || roll==6 || roll ==8 || roll==9 || roll==10)
printf("\nPoint to make is: %d\n", roll);
if(roll==7 || roll==11)
{
chipBalance+=bet;
printf("* * * You Win! * * *\n");
printf("\n You now have %d chips!\n", chipBalance);
printf("\n Thanks for playing!\n");
gamesWon++;
}
else if(roll==2 || roll==3 || roll==12)
{
chipBalance-=bet;
printf("* * * You Lose * * *\n");
printf("\n You now have %d chips!\n", chipBalance);
printf("\n Thanks for playing!\n");
gamesLost++;
}
else
{
do
{
die_3= 1+ rand() % 6;
die_4= 1+ rand() % 6;
roll_2=die_3 + die_4;
printf("\n|--> rolled: %d + %d = %d\n",die_3, die_4, roll_2);
if(roll_2==roll)
{
chipBalance+=bet;
printf("\n* * * You Win * * *\n\n");
printf("\n You now have %d chips!\n", chipBalance);
printf("\n Thanks for playing!\n");
gamesWon++;
}
}while(roll_2 != 7);
chipBalance-=bet;
printf("You Lose");
printf("\n You now have %d chips!\n", chipBalance);
printf("\n Thanks for playing!\n");
gamesLost++;
if (chipBalance <= 0)
{
printf( "\n Sorry, you're all out of chips\n\n");
printf("\n *** GAME OVER ***\n\n");
printf("\n Thanks for playing!\n\n\n");
}
if(answer != 'y');
{
printf("\nGames played: %d\n\n",play);
printf("|--> Games won: %d\n", gamesWon);
printf("|--> Games lost: %d\n", gamesLost);
printf("|--> Chips left: %d\n\n", chipBalance);
printf("\n Thanks for playing!\n");
return;
}
}
main();
}
|