Thread: Dice Game (Fifty)

  1. #31
    Registered User
    Join Date
    Sep 2017
    Posts
    23
    Quote Originally Posted by Hodor View Post
    Please don't use things such as char toPlay1 = NULL; Assigning NULL to a character variable is extremely uncommon (I can't recall ever seeing that used) and makes scanning code for mistakes more difficult.
    Thank you for the tip. I barely know what I'm doing but I will certainly try to remember this point.

  2. #32
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by PhantomJoe View Post
    I've added some comments to your reply to address each of your points to help me organize my thoughts.
    haha ( excuse me for chuckling) now you know why the "infinite loop" was not happening?

    1. as post #19 the_jackass pointed out as well your checks for 50 or greater are in the wrong place, or would be better served being somewhere else within your loop,

    you're relying on all of your conditions to get you out of your while loop no matter what. Making your if ( quit == 'q' ) obsolete

    You are using an algorithm that has the ability to reset the a value to zero.

    So it is not necessarily going into an infinite loop. it might just be that 50 or greater has never been met yet.

    It was main return 0 that was giving you false readings. it'd loop once then hit the return 0 then do just that return 0 then exit the function.

    if you look at post #29 I give you an idea that can be used to set your other condition for exiting the while loop and preventing it from going any further in rolling the die when it is no longer needed. If you go back and read #19 you will hopefully see why you're needing to check the total score for each player each where needed before rolling , or allowing another roll of the dice to take place.

    nulling char
    Code:
    char mychar = '\0';
    works , as even I have had to change them each time along with your usage of printf_s and scanf_s

    because I have already complete this on my side, and I know because of that, it takes awhile for one of the players to reach 50, I am going to give you that little piece of the missing puzzle. to stop that loop and make it wait while inside of it.

    Code:
        
               printf("\nplayer 1 hit enter to roll\n");
                
                getchar();
    getchar() waits for input just hit enter to get it to go past it.
    Code:
    quit = getchar()
    returns the char that is pressed. that should get you to be able to look at your code results to help you see if the rest of it is ok, by preventing it from looking like it is in an infinite loop,
    when really it just has not gotten a total score of 50 yet so it just spins around running your code, and resetting it to zero again, and again, and again, as it is coded to do when it gets double 3's.


    and check out post # 15 as well

    Last edited by userxbw; 10-25-2017 at 08:21 PM.

  3. #33
    Registered User
    Join Date
    Sep 2017
    Posts
    23
    Quote Originally Posted by userxbw View Post
    haha ( excuse me for chuckling) now you know why the "infinite loop" was not happening?

    1. as post #19 the_jackass pointed out as well your checks for 50 or greater are in the wrong place, or would be better served being somewhere else within your loop,

    you're relying on all of your conditions to get you out of your while loop no matter what. Making your if ( quit == 'q' ) obsolete

    You are using an algorithm that has the ability to reset the a value to zero.

    So it is not necessarily going into an infinite loop. it might just be that 50 or greater has never been met yet.

    It was main return 0 that was giving you false readings. it'd loop once then hit the return 0 then do just that return 0 then exit the function.

    if you look at post #29 I give you an idea that can be used to set your other condition for exiting the while loop and preventing it from going any further in rolling the die when it is no longer needed. If you go back and read #19 you will hopefully see why you're needing to check the total score for each player each where needed before rolling , or allowing another roll of the dice to take place.

    nulling char
    Code:
    char mychar = '\0';
    works , as even I have had to change them each time along with your usage of printf_s and scanf_s

    because I have already complete this on my side, and I know because of that, it takes awhile for one of the players to reach 50, I am going to give you that little piece of the missing puzzle. to stop that loop and make it wait while inside of it.

    Code:
        
               printf("\nplayer 1 hit enter to roll\n");
                
                getchar();
    getchar() waits for input just hit enter to get it to go past it.
    Code:
    quit = getchar()
    returns the char that is pressed. that should get you to be able to look at your code results to help you see if the rest of it is ok, by preventing it from looking like it is in an infinite loop,
    when really it just has not gotten a total score of 50 yet so it just spins around running your code, and resetting it to zero again, and again, and again, as it is coded to do when it gets double 3's.


    and check out post # 15 as well

    I see that I had return 0 in the wrong place so thank you for that. I've moved it and made a few other changes like changing the condition for the while loop and adding a check for score total right after each player's roll. However, I still do not understand how to end the loop when a player reaches 50 or more.

    Here's what it looks like now:
    Code:
    int main()
    {
    	//declare variables
    	int My_dice1;
    	int My_dice2;
    	int Your_dice1;
    	int Your_dice2;
    	int My_result = 0;
    	int Your_result = 0;
    	int total;
    	char quit = NULL;
    	char start;
    	char mychar = '\0';
    
    
    	srand((unsigned)time(NULL));	//Seed random function with current time
    
    
    									//Introductory message explaining what the program does and how the game is played.
    	printf_s("This program will simulate the dice game Fifty which requires 2 players with each player taking turns to roll 2 die.\n"
    		"The goal of Fifty is to be the first player to reach 50 points.  You get points by rolling doubles.\n"
    		"All doubles except 3s and 6s score 5 points.  Double 6s are worth 25 points and double 3s wipe out the players entire score\n"
    		"and the player must start again at 0.  Non-double rolls are 0 points.\n"
    		"Press q to quit.\n");
    
    
    
    
    	//Start game rules	
    	printf("Player 1's turn.  Press 's' to start.\n");
    	scanf_s("%c", &start);
    
    
    	if (start == 's')  //check if player actually pressed 's', only then execute the loop
    	{
    		while (quit != 'q')
    		{
    			printf("\nPlayer 1's turn\n");
    			My_dice1 = rand() % 6 + 1;
    			printf("Player 1's first die is %d\n", My_dice1);
    			My_dice2 = rand() % 6 + 1;
    			printf("Player 2's second die is %d\n", My_dice2);
    			total = (My_dice1 + My_dice2);
    
    
    			//Check if players has doubles
    			if (My_dice1 == My_dice2)
    			{
    				//Check for double sixes
    				if (total == 12) {
    					My_result = My_result + 25;
    					//Add 25 points to the sum
    				}//Check for double sixes end brace
    
    
    				 //Check for doule threes
    				else if (total == 6) {
    					My_result = 0;
    					printf("You rolled double 3s and your score has been reset to 0.\n");
    					//Assign zero to the sum
    				}//else if end brace
    
    
    				else {
    					My_result = My_result + 5;
    					//Executes for remaining other doubles
    					//Add 5 points to the sum
    				}//else end brace
    
    
    			}//end brace for the doubles check if statement for player1
    
    
    			printf("Player 1's score is %d \n", My_result);
    			if (My_result < 50)
    			{
    				printf("\nPlayer 2's turn\n");
    				Your_dice1 = rand() % 6 + 1;
    				printf("Player 2's first die is %d\n", Your_dice1);
    				Your_dice2 = rand() % 6 + 1;
    				printf("Player 2's second die is %d\n", Your_dice2);
    				total = (Your_dice1 + Your_dice2);
    			}//end brace for if less than 50 check
    			else
    			{
    				printf("Contratulations, Player 1 is the winner!\n");
    			}
    
    
    
    
    			//Check if players has doubles
    			if (Your_dice1 == Your_dice2)
    			{
    				//Check for double sixes
    				if (total == 12)
    				{
    					Your_result = Your_result + 25;
    					//Add 25 points to the sum
    				}//Check for double sixes end brace
    				 //Check for doule threes
    				else if (total == 6)
    				{
    					Your_result = 0;
    					printf("You rolled double 3s and your score has been reset to 0.\n");
    					//Assign zero to the sum
    				}//else if end brace
    				else {
    					Your_result = Your_result + 5;
    					//Executes for remaining other doubles
    					//Add 5 points to the sum
    				}//else end brace
    			}//end brace for the doubles check if statement for player2
    			printf("Player 2's score is %d \n", Your_result);
    			if (Your_result > 50)
    			{
    				printf("Contratulations, Player 2 is the winner!\n");
    			}
    
    
    		}//while loop end brace
    	}//if start end brace
    	return 0;
    }//main end brace

  4. #34
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <string.h>
    
    
    int main()
    {
        //declare variables
        int My_dice1;
        int My_dice2;
        int Your_dice1;
        int Your_dice2;
        int My_result = 0;
        int Your_result = 0;
        int total;
        char quit = '\0'; // <-- equals NULL
        char start;
    //    char mychar = '\0'; // this was an example how to NULL your char
     
     
        srand((unsigned)time(NULL));    //Seed random function with current time
                                         //Introductory message explaining what the program does and how the game is played.
        printf("This program will simulate the dice game Fifty which requires 2 players with each player taking turns to roll 2 die.\n"
            "The goal of Fifty is to be the first player to reach 50 points.  You get points by rolling doubles.\n"
            "All doubles except 3s and 6s score 5 points.  Double 6s are worth 25 points and double 3s wipe out the players entire score\n"
            "and the player must start again at 0.  Non-double rolls are 0 points.\n"
            "Press q to quit.\n");
     
       //Start game rules  
        printf("Player 1's turn.  Press 's' to start.\n");
        scanf("%c", &start);
        if (start == 's')  //check if player actually pressed 's', only then execute the loop
        {
            while (quit != 'q')
            {
                printf("\nPlayer 1's turn\n");
                My_dice1 = rand() % 6 + 1;
                printf("Player 1's first die is %d\n", My_dice1);
                My_dice2 = rand() % 6 + 1;
                printf("Player 2's second die is %d\n", My_dice2);
                total = (My_dice1 + My_dice2);
                 
                //Check if players has doubles
                if (My_dice1 == My_dice2)
                {
                    //Check for double sixes
                     //Add 25 points to the sum
                        if (total == 12) 
                        { My_result = My_result + 25; }//Check for double sixes end brace
                      //Check for doule threes
                    else if (total == 6) 
                    {
                        My_result = 0;  //Assign zero to the sum
                        printf("You rolled double 3s and your score has been reset to 0.\n");          
                    }//else if end brace
                    else //Executes for remaining other doubles  //Add 5 points to the sum
                    {
                        My_result = My_result + 5;                    
                    }//else end brace
                 }//end brace for the doubles check if statement for player1
                printf("Player 1's score is %d \n", My_result);
                //////////////////////////////////////////////////////////////
                /************************************************************
                 * 
                 * put this in you code too so you can see what is does
                 * 
                 * ***********************************************************/
                 printf("Hit Enter to roll dice\n");
                 getchar();
                 /**********************************************************
                  * *********************************************************
                  *  *****************************************************
                  * ********************************************************
                  * *********************************************************/
          
                if (My_result < 50)
                {
                    printf("\nPlayer 2's turn\n");
                    Your_dice1 = rand() % 6 + 1;
                    printf("Player 2's first die is %d\n", Your_dice1);
                    Your_dice2 = rand() % 6 + 1;
                    printf("Player 2's second die is %d\n", Your_dice2);
                    total = (Your_dice1 + Your_dice2);
                }//end brace for if less than 50 check
                else
                {
                    printf("Congratulations, Player 1 is the winner!\n");
                    // Here game is over 
                    // you're missing the assignment to quit
                    // so it will quit 
                    // what letter is quit looking for?
                    // quit = ??
                }
                 //Check if players has doubles
                if (Your_dice1 == Your_dice2)
                {
                    //Check for double sixes
                    if (total == 12)
                    {
                        Your_result = Your_result + 25;
                        //Add 25 points to the sum
                    }//Check for double sixes end brace
                     //Check for double threes
                    else if (total == 6)
                    {
                        Your_result = 0;
                        printf("You rolled double 3s and your score has been reset to 0.\n");
                        //Assign zero to the sum
                    }//else if end brace
                    else {
                        Your_result = Your_result + 5;
                        //Executes for remaining other doubles
                        //Add 5 points to the sum
                    }//else end brace
                }//end brace for the doubles check if statement for player2
                printf("Player 2's score is %d \n", Your_result);
                if (Your_result > 50)
                {
                    printf("Contratulations, Player 2 is the winner!\n");
                    // quit = ?? //<------------------------
                }
     
     
            }//while loop end brace
        }//if start end brace
        // your data is held within the main function
        // so the program will see it values
        // so when loops finishes print out results here
        printf("look what I can print here\n");
        if( My_result < Your_result)
            printf("Player 2 is the winner with %d points\n", Your_result);
        else
            printf("Player 1 is the winner with %d points\n", My_result);
            
        printf("totals are player 1 %d, plyer 2 %d\n", My_result, Your_result);
    
    // that is an example it can be changed 
    // to suit the needs of the assignment. 
    // or not used at all.
        
        
        
        
        return 0;
    }//main end brace
    Last edited by userxbw; 10-26-2017 at 05:47 PM.

  5. #35
    Banned
    Join Date
    Aug 2017
    Posts
    861
    nothing
    Last edited by userxbw; 10-26-2017 at 05:35 PM.

  6. #36
    Registered User
    Join Date
    Sep 2017
    Posts
    23
    Met again with my teacher tonight and while I wasn't a whole lot wrong in terms of needing to rewrite tons of code I did have a fundamental error in the while condition. It should have been joined with AND instead of OR.

    Here's my current code which plays the game for the 2 players (which is still an issue) but the loop is now functioning correctly.
    Code:
    int main()
    {
    	//declare variables
    	int My_dice1;
    	int My_dice2;
    	int Your_dice1;
    	int Your_dice2;
    	int My_result = 0;
    	int Your_result = 0;
    	int total;
    	char quit = NULL;
    	char start;
    	
    
    
    	srand((unsigned)time(NULL));	//Seed random function with current time
    
    
    									//Introductory message explaining what the program does and how the game is played.
    	printf_s("This program will simulate the dice game Fifty which requires 2 players with each player taking turns to roll 2 die.\n"
    		"The goal of Fifty is to be the first player to reach 50 points.  You get points by rolling doubles.\n"
    		"All doubles except 3s and 6s score 5 points.  Double 6s are worth 25 points and double 3s wipe out the players entire score\n"
    		"and the player must start again at 0.  Non-double rolls are 0 points.\n"
    		"Press q to quit.\n");
    
    
    
    
    	//Start game rules	
    	printf("Player 1's turn.  Press 's' to start.\n");
    	scanf_s("%c", &start);
    
    
    	if (start == 's')  //check if player actually pressed 's', only then execute the loop
    	{
    		while (My_result < 50 && Your_result < 50) 
    		{
    			printf("\nPlayer 1's turn\n");
    			My_dice1 = rand() % 6 + 1;
    			printf("Player 1's first die is %d\n", My_dice1);
    			My_dice2 = rand() % 6 + 1;
    			printf("Player 1's second die is %d\n", My_dice2);
    			total = (My_dice1 + My_dice2);
    
    
    			//Check if players has doubles
    			if (My_dice1 == My_dice2)
    			{
    				//Check for double sixes
    				if (total == 12) {
    					My_result = My_result + 25;
    					//Add 25 points to the sum
    				}//Check for double sixes end brace
    
    
    				 //Check for doule threes
    				else if (total == 6) {
    					My_result = 0;
    					printf("You rolled double 3s and your score has been reset to 0.\n");
    					//Assign zero to the sum
    				}//else if end brace
    
    
    				else {
    					My_result = My_result + 5;
    					//Executes for remaining other doubles
    					//Add 5 points to the sum
    				}//else end brace
    
    
    			}//end brace for the doubles check if statement for player1
    
    
    			printf("Player 1's score is %d \n", My_result);
    			if (My_result < 50)
    			{
    				printf("\nPlayer 2's turn\n");
    				Your_dice1 = rand() % 6 + 1;
    				printf("Player 2's first die is %d\n", Your_dice1);
    				Your_dice2 = rand() % 6 + 1;
    				printf("Player 2's second die is %d\n", Your_dice2);
    				total = (Your_dice1 + Your_dice2);
    
    
    				//Check if players has doubles
    				if (Your_dice1 == Your_dice2)
    				{
    					//Check for double sixes
    					if (total == 12)
    					{
    						Your_result = Your_result + 25;
    						//Add 25 points to the sum
    					}//Check for double sixes end brace
    					 //Check for doule threes
    					else if (total == 6)
    					{
    						Your_result = 0;
    						printf("You rolled double 3s and your score has been reset to 0.\n");
    						//Assign zero to the sum
    					}//else if end brace
    					else {
    						Your_result = Your_result + 5;
    						//Executes for remaining other doubles
    						//Add 5 points to the sum
    					}//else end brace
    				}//end brace for the doubles check if statement for player2
    				printf("Player 2's score is %d \n", Your_result);
    
    
    
    
    			}//end brace for if less than 50 check
    			else
    			{
    				printf("Contratulations, Player 1 is the winner!\n");
    			}
    
    
    
    
    			
    			if (Your_result >= 50)
    			{
    				printf("Contratulations, Player 2 is the winner!\n");
    			}
    
    
    		}//while loop end brace
    	}//if start end brace
    	return 0;
    }//main end brace

  7. #37
    Banned
    Join Date
    Aug 2017
    Posts
    861
    it would have still worked:
    Code:
    #include <stdio.h>
    
    int main (void)
    {
        int a = 0;
        char quit;
        
        while (quit != 'q')
        {
            printf("%d: quit != 'q'\n", a);
            
            if (a == 5)
                quit = 'q';
                a++;
        }
    
        printf("quit = %c\n", quit);
    return 0;
    }
    results
    Code:
    userx@slackwhere:~/bin
    userx@slackwhere:~/bin
    $ ./while_not_q
    0: quit != 'q'
    1: quit != 'q'
    2: quit != 'q'
    3: quit != 'q'
    4: quit != 'q'
    5: quit != 'q'
    quit = q
    and in your code
    Code:
    //    char quit = '\0'; <-- no longer being used. So get rid of it right?
    Code:
     
                }//end brace for if less than 50 check
                else
                {
                    printf("Contratulations, Player 1 is the winner!\n");
                    quit = 'q';
    
    
                }
     
     
     
     
                 
                if (Your_result >= 50)
                {
                    printf("Contratulations, Player 2 is the winner!\n");
                     quit = 'q';
    
    
                }


    is it suppose to stop between users/players?
    Last edited by userxbw; 10-26-2017 at 08:53 PM.

  8. #38
    Registered User
    Join Date
    Sep 2017
    Posts
    23
    So I'm really close. Here's my updated code. I've got the back and forth in there but it's not working quite right. The player 1 button-press doesn't work but the player 2 button-press is working perfectly. I built them the same way so I'm struggling to see why one works but the other doesn't.
    Code:
    int main()
    {
        //declare variables
        int My_dice1;
        int My_dice2;
        int Your_dice1;
        int Your_dice2;
        int My_result = 0;
        int Your_result = 0;
        int total;
        char quit = NULL;
        char start;
        char myKey = NULL;
        char yourKey = NULL;
    
    
        srand((unsigned)time(NULL));    //Seed random function with current time
    
    
                                        //Introductory message explaining what the program does and how the game is played.
        printf_s("This program will simulate the dice game Fifty which requires 2 players with each player taking turns to roll 2 die.\n"
            "The goal of Fifty is to be the first player to reach 50 points.  You get points by rolling doubles.\n"
            "All doubles except 3s and 6s score 5 points.  Double 6s are worth 25 points and double 3s wipe out the players entire score\n"
            "and the player must start again at 0.  Non-double rolls are 0 points.\n"
            "Press q to quit.\n");
    
    
    
    
        //Start game rules    
        printf("Player 1's turn.  Press 's' to start.\n");
        scanf_s("%c", &start);
    
    
        if (start == 's')  //check if player actually pressed 's', only then execute the loop
        {
            while ((My_result < 50 && Your_result < 50) || (quit != 'q'))
            {
                printf("Player 1, press 'a' to roll your dice or press 'q' to quit.\n");
                scanf_s("%c", &myKey);
                if (myKey == 'a')
                {
                    printf("\nPlayer 1's turn\n");
                    My_dice1 = rand() % 6 + 1;
                    printf("Player 1's first die is %d\n", My_dice1);
                    My_dice2 = rand() % 6 + 1;
                    printf("Player 1's second die is %d\n", My_dice2);
                    total = (My_dice1 + My_dice2);
                
                    //Check if players has doubles
                    if (My_dice1 == My_dice2)
                    {
                        //Check for double sixes
                        if (total == 12) {
                            My_result = My_result + 25;
                            //Add 25 points to the sum
                        }//Check for double sixes end brace
    
    
                         //Check for doule threes
                        else if (total == 6) {
                            My_result = 0;
                            printf("You rolled double 3s and your score has been reset to 0.\n");
                            //Assign zero to the sum
                        }//else if end brace
    
    
                        else {
                            My_result = My_result + 5;
                            //Executes for remaining other doubles
                            //Add 5 points to the sum
                        }//else end brace
    
    
                    }//end brace for the doubles check if statement for player1
                
    
    
                    printf("Player 1's score is %d \n", My_result);
                }//if myKey end brace
                    if (My_result < 50)
                    {
                        printf("Player 2, press 'b' to roll your dice or press 'q' to quit.\n");
                        scanf_s("%c", &yourKey);
                        if (yourKey == 'b')
                        {
                            printf("\nPlayer 2's turn\n");
                            Your_dice1 = rand() % 6 + 1;
                            printf("Player 2's first die is %d\n", Your_dice1);
                            Your_dice2 = rand() % 6 + 1;
                            printf("Player 2's second die is %d\n", Your_dice2);
                            total = (Your_dice1 + Your_dice2);
                        
                            //Check if players has doubles
                            if (Your_dice1 == Your_dice2)
                            {
                                //Check for double sixes
                                if (total == 12)
                                {
                                    Your_result = Your_result + 25;
                                    //Add 25 points to the sum
                                }//Check for double sixes end brace
                                 //Check for doule threes
                                else if (total == 6)
                                {
                                    Your_result = 0;
                                    printf("You rolled double 3s and your score has been reset to 0.\n");
                                    //Assign zero to the sum
                                }//else if end brace
                                else {
                                    Your_result = Your_result + 5;
                                    //Executes for remaining other doubles
                                    //Add 5 points to the sum
                                }//else end brace
                            }//end brace for the doubles check if statement for player2
                        }//if yourKey end brace
                        printf("Player 2's score is %d \n", Your_result);
    
    
    
    
                    }//end brace for if less than 50 check
                    else
                    {
                        printf("Contratulations, Player 1 is the winner!\n");
                    }
    
    
    
    
    
    
                    if (Your_result >= 50)
                    {
                        printf("Contratulations, Player 2 is the winner!\n");
                    }
    
    
                }//while loop end brace
            }//if start end brace
            return 0;
        
    }//main end brace

  9. #39
    Banned
    Join Date
    Aug 2017
    Posts
    861
    all them changes are unneeded, you just needed to add your scanf("%c", start); because that char can be used again. and remove your char quit.
    then see where you're at after you run it.
    I was just showing you how quit could have been used had it been used.

    you just needed to make it == equal q by assigning the value of q to it.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <string.h>
    
    int main()
    {
        //declare variables
        int My_dice1;
        int My_dice2;
        int Your_dice1;
        int Your_dice2;
        int My_result = 0;
        int Your_result = 0;
        int total;
        char start;
         
     
     
        srand((unsigned)time(NULL));    //Seed random function with current time
     
     
                                        //Introductory message explaining what the program does and how the game is played.
        printf("This program will simulate the dice game Fifty which requires 2 players with each player taking turns to roll 2 die.\n"
            "The goal of Fifty is to be the first player to reach 50 points.  You get points by rolling doubles.\n"
            "All doubles except 3s and 6s score 5 points.  Double 6s are worth 25 points and double 3s wipe out the players entire score\n"
            "and the player must start again at 0.  Non-double rolls are 0 points.\n"
            "Press q to quit.\n");
     
     
     
     
        //Start game rules  
        printf("Player 1's turn.  Press 's' to start.\n");
        scanf("%c", &quit); // use quit if you're going to quit
     
     
        if (start == 's')  //check if player actually pressed 's', only then execute the loop
        {
            while (My_result < 50 && Your_result < 50) 
            {
                // player one is already going to roll
                // he started the game 
                // it blast past here on the first
                // time around. but besides that it works. 
                
                printf("\nPlayer One: Hit enter to roll\n");
                scanf("%c", &start);
                
                printf("\nPlayer 1's turn\n");
                My_dice1 = rand() % 6 + 1;
                printf("Player 1's first die is %d\n", My_dice1);
                My_dice2 = rand() % 6 + 1;
                printf("Player 1's second die is %d\n", My_dice2);
                total = (My_dice1 + My_dice2);
     
     
                //Check if players has doubles
                if (My_dice1 == My_dice2)
                {
                    //Check for double sixes
                    if (total == 12) {
                        My_result = My_result + 25;
                        //Add 25 points to the sum
                    }//Check for double sixes end brace
     
     
                     //Check for doule threes
                    else if (total == 6) {
                        My_result = 0;
                        printf("You rolled double 3s and your score has been reset to 0.\n");
                        //Assign zero to the sum
                    }//else if end brace
     
     
                    else {
                        My_result = My_result + 5;
                        //Executes for remaining other doubles
                        //Add 5 points to the sum
                    }//else end brace
     
     
                }//end brace for the doubles check if statement for player1
                
                printf("\nPlayer Two: Hit enter to roll\n");
                scanf("%c", &start);
                
                printf("Player 1's score is %d \n", My_result);
                if (My_result < 50)
                {
                    printf("\nPlayer 2's turn\n");
                    Your_dice1 = rand() % 6 + 1;
                    printf("Player 2's first die is %d\n", Your_dice1);
                    Your_dice2 = rand() % 6 + 1;
                    printf("Player 2's second die is %d\n", Your_dice2);
                    total = (Your_dice1 + Your_dice2);
     
     
                    //Check if players has doubles
                    if (Your_dice1 == Your_dice2)
                    {
                        //Check for double sixes
                        if (total == 12)
                        {
                            Your_result = Your_result + 25;
                            //Add 25 points to the sum
                        }//Check for double sixes end brace
                         //Check for doule threes
                        else if (total == 6)
                        {
                            Your_result = 0;
                            printf("You rolled double 3s and your score has been reset to 0.\n");
                            //Assign zero to the sum
                        }//else if end brace
                        else {
                            Your_result = Your_result + 5;
                            //Executes for remaining other doubles
                            //Add 5 points to the sum
                        }//else end brace
                    }//end brace for the doubles check if statement for player2
                    printf("Player 2's score is %d \n", Your_result);
     
     
     
     
                }//end brace for if less than 50 check
                else
                {
                    printf("Contratulations, Player 1 is the winner!\n");
                }
                  
                if (Your_result >= 50)
                {
                    printf("Contratulations, Player 2 is the winner!\n");
                }
     
     
            }//while loop end brace
        }//if start end brace
        return 0;
    }//main end brace
    if you still HAVE to make it have the option of q for quit then the loop condition only needs to be

    Code:
    while ( quit != q)
    {
    
    
    printf("hit enter to roll or q to quit\n);
    scanf("%c", start); // or quit as long as all of them match the char being used. 
    ...... 
    
    
    // then down here can this can be added BUT ONLY IF YOU NEED THAT OPTION.
    // the assigning the q to quit takes care of stopping the loop also when one gets 50 or greater. 
    
          else
                {
                    printf("Contratulations, Player 1 is the winner!\n");
                    quit = 'q';
    
    
                }
     
     
     
     
                 
                if (Your_result >= 50)
                {
                    printf("Contratulations, Player 2 is the winner!\n");
                     quit = 'q';
    
    
    }
    then put them quit = 'q' where I showed you on top of that one changed that asked for a q the you used the scanf to get one. leave the rest alone. and that should work that way as well.
    Last edited by userxbw; 10-26-2017 at 09:43 PM.

  10. #40
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Reusing varitables

    Code:
    #include <stdio.h>
     
    int main (void)
    {
        int a = 0;
        char start;
        
        printf("enter s to start\n");
        scanf("%c", &start);
        
        if ( start == 's')
            while (start != 'q')
            {
                printf("%d: start != 'q'\n", a);
            
                if (a == 5)
                    start = 'q';
                    a++;
            }
       else
         printf("what no want to start?\n");
            
            
        printf("start = %c\n", start);
    return 0;
    }
    Results
    Code:
    userx@slackwhere:~/bin
    $ ./while_not_q
    enter s to start
    s
    0: start != 'q'
    1: start != 'q'
    2: start != 'q'
    3: start != 'q'
    4: start != 'q'
    5: start != 'q'
    start = q
    userx@slackwhere:~/bin
    just hitting enter gets this result
    Code:
    userx@slackwhere:~/bin
    $ ./while_not_q
    enter s to start
    
    what no want to start?
    start =
    Last edited by userxbw; 10-26-2017 at 09:40 PM.

  11. #41
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by userxbw View Post
    where here:
    Code:
                    for (; left > 0; left -= newW);
                        for (; top > 0; top -= newH);
    
                    for (x = left; x < img.screenW; x += newW)
                        for (y = top; y < img.screenH; y += newH)
    
                    imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, h,w, x, y, newW / space_tile_gap((rand() % 3)) , newH / space_tile_gap((rand() % 3)));
    if I was to bracket my for loops then it would not render properly .
    If you had used parentheses properly the code would be much easier to understand:
    Code:
    for (; left > 0; left -= newW)
    {
        /* do nothing here */
    }
    
    for (; top > 0; top -= newH)
    {
        /* do nothing here */
    }
     
    for (x = left; x < img.screenW; x += newW)
    {
        for (y = top; y < img.screenH; y += newH)
        {
            imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, h,w, x, y, newW / space_tile_gap((rand() % 3)) , newH / space_tile_gap((rand() % 3)));
        }
    }
    As it stands, your poor indentation illustrates why a style of always using parentheses is better. That said, you could have written the empty for loop bodies without parentheses and still have them be readable with suitable indentation, e.g.,
    Code:
    for (; left > 0; left -= newW)
        /* do nothing here */;
    
    for (; top > 0; top -= newH)
        /* do nothing here */;
    Although it is possible to argue that the semi-colon at the end might be obscured by the comment, so maybe omitting the comment would be better.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #42
    Banned
    Join Date
    Aug 2017
    Posts
    861
    the last time I tried putting brackets around it (the brackets assignment may have been different,) but, it just screwed it up so I put it back the way it was then it worked again. so I left it alone then got on with the rest of what I had to do. but thanks. I'll try that again and let you know in a minute or so...

    back.. ok smarty ...... it worked... thanks

    Code:
            for (; left > 0; left -= newW); {}
                for (; top > 0; top -= newH); {}
    
            for (x = left; x < img.screenW; x += newW)
            {
                for (y = top; y < img.screenH; y += newH)
                    imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, h,w, x, y, newW, newH);
            }
    I didn't put that much thought into it.
    Last edited by userxbw; 10-26-2017 at 10:02 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help On Keeping Score For Dice Game
    By AdAstra in forum C Programming
    Replies: 1
    Last Post: 03-18-2011, 06:08 PM
  2. Help With Dice Game
    By CaliJoe in forum C++ Programming
    Replies: 1
    Last Post: 03-11-2009, 04:08 PM
  3. Help With Dice Game
    By CaliJoe in forum C++ Programming
    Replies: 2
    Last Post: 03-10-2009, 04:35 PM
  4. craps game & dice game..
    By cgurl05 in forum C Programming
    Replies: 3
    Last Post: 03-25-2006, 07:58 PM
  5. Craps the Dice Game
    By ketchup57v in forum Game Programming
    Replies: 11
    Last Post: 12-01-2001, 04:53 AM

Tags for this Thread