Thread: Craps game

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    34

    Craps game

    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;
    		}}

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Where are you telling it not to continue into the next loop? while(TRUE) is never going to end since TRUE is a constant. It's like doing while(1). A better way might be to have a variable called something like keep_going. Set it to TRUE initially and then you can do while(keep_going). When you want to stop looping just do keep_going = FALSE.
    If you understand what you're doing, you're not learning anything.

  3. #3
    also void main() = NO NO!@%#$@^!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please comment on my c++ game
    By MegaManZZ in forum Game Programming
    Replies: 10
    Last Post: 01-22-2008, 11:03 AM
  2. Craps Game
    By TWIXMIX in forum Game Programming
    Replies: 5
    Last Post: 06-12-2004, 07:47 PM
  3. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  4. help with a craps game!
    By Jessie in forum C Programming
    Replies: 10
    Last Post: 10-16-2002, 09:19 AM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM