I am having trouble with this game i wrote. If the user rolls a 7, 11, 2,3,or 12, the game is supposed to end. When i recieve these numbers, the game roll the dice anyways. Any suggestions...Thanks
Code:
#define TRUE 1
#define FALSE !TRUE
int rnd(int range);
int roll(void);
void seedrnd(void);
void main()
{
int x, Play,pot,bet,backbet,newNumber=0;
/*setup*/
seedrnd();
printf(" !!Vegas Casino Craps!!\n");
printf(" ______________________________________________\n\n");
Play=TRUE;
pot=200; //gives the player $200$
while (Play)
{
do
{
printf(" You have %d dollars in your pot\n\n", pot);
printf(" Enter Your Bet: $$");
scanf ("%d", &bet);
if (bet<1 )
printf("You cant bet below 1$!!\n\n");
else
if (bet>pot)
printf("You dont have %d dollars!!\n\n", bet);
}
while (bet<1 || bet>pot);
x=roll(); //roll the dice
printf("The roll was %d.\n", x);
break;
}
/* A switch to set something to the rolls.
* A 7 and 11 win and double your bet,
* 2, 3, or 12 lose and you lose your bet.*/
switch(x)
{
case 7:
case 11:
printf(" You Win!!\n");
pot += bet;
printf("You now have %d$$ in your pot!\n",pot);
break;
case 2:
case 3:
case 12:
printf(" Craps!! YOU LOSE!\n");
pot -= bet;
printf("That sucks! You have %d$$ left, keep trying!\n",pot);
break;
default: // For everything else
newNumber = x; // Setting x to the roll
printf(" Your point is %d.\n", newNumber);
printf(" Enter a back-bet below $%d$:", bet*2);
scanf ("%d", &backbet);
if (backbet > bet*2)
{ printf("Cant you read motherI am sillyI am sillyI am sillyI am sillyer?\n\n");
printf(" Enter a back-bet BELOW $%d$!!:", bet*2);
scanf ("%d", &backbet);}
}
/* This next loop rolls the dice again to see if you get your
* point again or 7. If you get a 7 before your point, you lose*/
while(TRUE)
{
x=roll(); //Rolling the dice
printf(" You rolled a %d\n",x);
if (x == newNumber)
{
printf(" You win!\n");
switch(x)
{
case 6:
case 8:
pot += (backbet*6/5) + bet;
break;
case 5:
case 9:
pot += (backbet*3/2) + bet;
break;
case 4:
case 10:
pot += (backbet*2) +bet;
break;
}break;
}
if (x == 7)
{
printf(" YOU GOT 7!! YOU LOSE!\n");
pot = pot - bet - backbet;
break;
}}