Can somebody please help with this craps modification?
Everything works fine, except when we get a win case, it won't loop back and play again. It just keeps winning. This is driving me nuts!
Code:
/*A player rolls two dice. If the sum is 7 or 11 on the first throw, the player wins.
If the sum is 2,3 or 12 (craps), the player loses. If the sum is
4,5,6,8,9 or 10 on the first throw, then that sum becomes the player's
point. To win, you must continue rolling the dice until you make your point
The player loses by rolling a 7 before making the point.
*/
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
//enumeration constants represent game status
enum Status{CONTINUE, WON, LOST};
//function prototype
int rollDice(void);
int winQuotes(void);
int loseQuotes(void);
int crapsGame(void);
int enterWager(void);
/*int enterWager(void)
{
double bankBalance;
double wager;
printf("Bank Balance = ");
scanf("%lf", &bankBalance);
printf("Balance is $%lf\n", bankBalance);
printf("Please enter a wager: ");
scanf("%lf", &wager);
printf("Please enter a wager: ");
scanf("%lf", &wager);
while(wager >= bankBalance)
{
printf("Can't bet more than you have.\nPlease enter valid wager: ");
scanf("%lf", &wager);
}//end while
}//end wager*/
int winQuotes(void)
{
int rn = rand() % 6;
switch(rn)
{
case 0:
printf("Very Lucky!\n");
break;
case 1:
printf("Big WINNER!!!\n");
break;
case 2:
printf("You WIN! PERFECT!\n");
break;
case 3:
printf("THE WINNER!\n");
break;
case 4:
printf("Hey there! You're cleaning me out over here!\n");
break;
case 5:
printf("Looks like I'm going broke! Stop winning so much!\n");
break;
}//end switch
}//end winQuotes
int loseQuotes(void)
{
int rn = rand() % 6;
switch(rn)
{
case 0:
printf("uh-oh! You lost\n");
break;
case 1:
printf("Big LOSER!!!\n");
break;
case 2:
printf("You LOSE! NOT PERFECT!\n");
break;
case 3:
printf("YOU LOSE!\n");
break;
case 4:
printf("Hey there! I'm cleaning you out over here!\n");
break;
case 5:
printf("HA! Looks like you're going broke! Keep it up!\n");
break;
}//end switch
}//end loseQuotes
//roll the dice, calculate sum and display results
int rollDice(void)
{
int die1; //first die
int die2; //second die
int workSum; //sum of dice
die1 = 1 + (rand()%6); //pick random die1 value
die2 = 1 + (rand()%6); //pick random die2 value
workSum = die1 + die2; //sum of the two die rolls
//display results of the roll
printf("Player rolled %d + %d = %d\n", die1, die2, workSum);
return workSum;
}//end rollDice
int main(void)
{
// int sum;//sum rolled dice
// int myPoint;
// double bankBalance;
//// double wager;
enum Status gameStatus;//can contain CONTINUE, WON, or LOST
//randomize RNG using time
srand(time(NULL));
// sum = rollDice(); //roll the dice
crapsGame();
}//end main
int crapsGame(void)
{
int sum;//sum rolled dice
int myPoint;
double bankBalance;
double wager;
printf("Bank Balance = ");
scanf("%lf", &bankBalance);
printf("Balance is $%lf\n", bankBalance);
printf("Please enter a wager: ");
scanf("%lf", &wager);
while(wager > bankBalance)
{
printf("Can't bet more than you have.\nPlease enter valid wager: ");
scanf("%lf", &wager);
}//end while
enum Status gameStatus;//can contain CONTINUE, WON, or LOST
sum = rollDice(); //roll the dice
while(bankBalance != 0)
{
//determine game status based on sum of dice
switch(sum)
{
//win on first roll
case 7:
case 11:
gameStatus = WON;
break;
//lose on first roll
case 2:
case 3:
case 12:
gameStatus = LOST;
break;
//remember point--if WIN or LOST has not been achieved
default:
gameStatus = CONTINUE;
myPoint = sum;
printf("Point is %d\n", myPoint);
break; //optional
}//end switch
//while game not complete
while(gameStatus == CONTINUE)
{
sum = rollDice(); // roll the dice again
//determine game status
if(sum == myPoint)//win by making point
{
gameStatus = WON;
}//end if
else
{
if(sum == 7)//lose by roling a 7
{
gameStatus = LOST; //game over
}//end if
}//end else
}//end while
if(gameStatus == WON)
{
printf("Player Wins\n");
bankBalance += wager;
printf("New Balance = $%lf\n", bankBalance);
winQuotes();
// break;
// printf("Please enter a wager: ");
// scanf("%lf", &wager);
//
// while(wager > bankBalance)
// {
// printf("Can't bet more than you have.\nPlease enter valid wager: ");
// scanf("%lf", &wager);
// }//end while
}//end if
if(gameStatus == LOST)
{
printf("Player Loses\n");
bankBalance -= wager;
printf("New Balance = $%lf\n", bankBalance);
loseQuotes();
// break;
// printf("Please enter a wager: ");
// scanf("%lf", &wager);
//
// while(wager > bankBalance)
// {
// printf("Can't bet more than you have.\nPlease enter valid wager: ");
// scanf("%lf", &wager);
// }//end while
}//end if
// printf("Please enter a wager: ");
// scanf("%lf", &wager);
//
// while(wager > bankBalance)
// {
// printf("Can't bet more than you have.\nPlease enter valid wager: ");
// scanf("%lf", &wager);
// }//end while
}//end while
}//end crapsGame
Any help is appreciated. Thanks in advance