Thread: Rock Paper Scissors Program help

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    18

    Rock Paper Scissors Program help

    hi im programming my first game and but a good dent into it however i got stuck. what im trying to do is an option to play again. if the user decides to play again then i want the options to execute again and if the user choses not to play again then i want the game to show the scores. does anyone know how to do that?

    here is what i have so far:
    Code:
    
    
    Code:
    // Purpose: Play the Rock-Paper-Scissors-Lizard-Spock Game
    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    
    
    int main() {
    int player_One_Choice, player_Two_Choice,ready,retry;
    printf ("Are YOU ready to play Rock-Paper-Scissors-Lizard-Spock? \n"); 
    printf ("0 for NO \n1 for YES ");
    scanf  ("%d", &ready);
       
    printf ("Player One!! ENTER YOUR CHOICE \n1 = Rock \n2 = Paper \n3 = Scissors \n4 = Lizard \n5 = Spock \n");
    scanf ( "%d", &player_One_Choice);
    
    
    printf ("Player Two!! ENTER YOUR CHOICE \n1 = Rock \n2 = Paper \n3 = Scissors \n4 = Lizard \n5 = Spock \n");
    scanf ( "%d", &player_Two_Choice);
    
    
    if (player_One_Choice == 1 && player_Two_Choice == 1 || player_One_Choice == 2 && player_Two_Choice == 2 || player_One_Choice == 3 && player_Two_Choice == 3 ||    player_One_Choice == 4 && player_Two_Choice == 4 || player_One_Choice == 5 && player_Two_Choice == 5){
    printf("\nPlayer 1 selected: %d\n", player_One_Choice);
    printf("\nPlayer 2 selected: %d\n", player_Two_Choice);
    printf("\nYou tied, we cant end things like this, TRY AGAIN!!!???\n0 for NO \n1 for YES \n");
           }
    if (player_One_Choice == 1 && player_Two_Choice == 4 || player_One_Choice == 1 && player_Two_Choice == 3 || player_One_Choice == 2 && player_Two_Choice == 1 ||    player_One_Choice == 2 && player_Two_Choice == 5 || player_One_Choice == 3 && player_Two_Choice == 2 || 
        player_One_Choice == 3 && player_Two_Choice == 4 || player_One_Choice == 4 && player_Two_Choice == 5 || player_One_Choice == 4 && player_Two_Choice == 2 || player_One_Choice == 5 && player_Two_Choice == 3 || player_One_Choice == 5 && player_Two_Choice == 1){
    printf("\nPlayer 1 selected: %d\n", player_One_Choice);
    printf("\nPlayer 2 selected: %d\n", player_Two_Choice);
    printf("\nPlayer 1, victory!, TRY AGAIN???\n0 for NO \n1 for YES \n");
           }
    if (player_One_Choice == 4 && player_Two_Choice == 1 || player_One_Choice == 3 && player_Two_Choice == 1 || player_One_Choice == 1 && player_Two_Choice == 2 ||    player_One_Choice == 5 && player_Two_Choice == 2 || player_One_Choice == 2 && player_Two_Choice == 3 || 
        player_One_Choice == 4 && player_Two_Choice == 3 || player_One_Choice == 5 && player_Two_Choice == 4 || player_One_Choice == 2 && player_Two_Choice == 4 || player_One_Choice == 3 && player_Two_Choice == 5 || player_One_Choice == 1 && player_Two_Choice == 5){
    printf("\nPlayer 1 selected: %d\n", player_One_Choice);
    printf("\nPlayer 2 selected: %d\n", player_Two_Choice);
    printf("\nPlayer 2, victory!, TRY AGAIN???\n 0 for NO \n1 for YES \n");
    
    
          }
    scanf ( "%d", &retry);
    return 0;
    }
    Last edited by Nick Tricarico; 10-10-2013 at 07:04 PM. Reason: typos

  2. #2
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    Put it in a while loop. for example
    Code:
    while ( playagain == 1 )
    {
    // all of your existing code
    
    print(would you like to play again 1 for yes, 0 for no) //Just an example based off of how I see you doing your user input
    scan playagain
    }
    print scores

  3. #3
    Registered User
    Join Date
    Oct 2013
    Posts
    18
    Quote Originally Posted by camel-man View Post
    Put it in a while loop. for example
    Code:
    while ( playagain == 1 )
    {
    // all of your existing code
    
    print(would you like to play again 1 for yes, 0 for no) //Just an example based off of how I see you doing your user input
    scan playagain
    }
    print scores
    so how do i fix up my code to put this in it

  4. #4
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    You just need to change the final scanf to read the variable ready instead of retry.
    Code:
    int main()
    {
    	int player_One_Choice, player_Two_Choice, ready, retry;
    	printf("Are YOU ready to play Rock-Paper-Scissors-Lizard-Spock? \n");
    	printf("0 for NO \n1 for YES ");
    	scanf("%d", &ready);
    
    	while(ready==1){
    
    	printf("Player One!! ENTER YOUR CHOICE \n1 = Rock \n2 = Paper \n3 = Scissors \n4 = Lizard \n5 = Spock \n");
    	scanf("%d", &player_One_Choice);
    
    
    	printf("Player Two!! ENTER YOUR CHOICE \n1 = Rock \n2 = Paper \n3 = Scissors \n4 = Lizard \n5 = Spock \n");
    	scanf("%d", &player_Two_Choice);
    
    
    	if (player_One_Choice == 1 && player_Two_Choice == 1 || player_One_Choice == 2 && player_Two_Choice == 2 || player_One_Choice == 3 && player_Two_Choice == 3 || player_One_Choice == 4 && player_Two_Choice == 4 || player_One_Choice == 5 && player_Two_Choice == 5)
    	{
    		printf("\nPlayer 1 selected: %d\n", player_One_Choice);
    		printf("\nPlayer 2 selected: %d\n", player_Two_Choice);
    		printf("\nYou tied, we cant end things like this, TRY AGAIN!!!???\n0 for NO \n1 for YES \n");
    	}
    	if (player_One_Choice == 1 && player_Two_Choice == 4 || player_One_Choice == 1 && player_Two_Choice == 3 || player_One_Choice == 2 && player_Two_Choice == 1 || player_One_Choice == 2 && player_Two_Choice == 5 || player_One_Choice == 3 && player_Two_Choice == 2 || player_One_Choice == 3 && player_Two_Choice == 4 || player_One_Choice == 4 && player_Two_Choice == 5 || player_One_Choice == 4 && player_Two_Choice == 2 || player_One_Choice == 5 && player_Two_Choice == 3 || player_One_Choice == 5 && player_Two_Choice == 1)
    	{
    		printf("\nPlayer 1 selected: %d\n", player_One_Choice);
    		printf("\nPlayer 2 selected: %d\n", player_Two_Choice);
    		printf("\nPlayer 1, victory!, TRY AGAIN???\n0 for NO \n1 for YES \n");
    	}
    	if (player_One_Choice == 4 && player_Two_Choice == 1 || player_One_Choice == 3 && player_Two_Choice == 1 || player_One_Choice == 1 && player_Two_Choice == 2 || player_One_Choice == 5 && player_Two_Choice == 2 || player_One_Choice == 2 && player_Two_Choice == 3 || player_One_Choice == 4 && player_Two_Choice == 3 || player_One_Choice == 5 && player_Two_Choice == 4 || player_One_Choice == 2 && player_Two_Choice == 4 || player_One_Choice == 3 && player_Two_Choice == 5 || player_One_Choice == 1 && player_Two_Choice == 5)
    	{
    		printf("\nPlayer 1 selected: %d\n", player_One_Choice);
    		printf("\nPlayer 2 selected: %d\n", player_Two_Choice);
    		printf("\nPlayer 2, victory!, TRY AGAIN???\n 0 for NO \n1 for YES \n");
    	}
    	scanf("%d", &ready);
    	}
    	return 0;
    }

  5. #5
    11DE784A SirPrattlepod's Avatar
    Join Date
    Aug 2013
    Posts
    485
    @camel-man: Line 8, ready is used unitialised

  6. #6
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    @SirPrattlepod the scanf is just above it

  7. #7
    Registered User
    Join Date
    Oct 2013
    Posts
    18
    Quote Originally Posted by SirPrattlepod View Post
    @camel-man: Line 8, ready is used unitialised
    I think he ment to make it retry

  8. #8
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    Quote Originally Posted by Nick Tricarico View Post
    I think he ment to make it retry
    There is no need to make another variable, it is redundant to do so.

  9. #9
    Registered User
    Join Date
    Oct 2013
    Posts
    18
    Quote Originally Posted by camel-man View Post
    There is no need to make another variable, it is redundant to do so.
    im still kinda lost lol

  10. #10
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    You could make another variable called 'Retry' yet it wouldnt serve much purpose if you can achieve the same desired loop with just one variable.

    for example you could do it this way

    Code:
    #include <stdio.h>
    
    
    int main()
    {
    	int player_One_Choice, player_Two_Choice, ready, retry = 1;
    	printf("Are YOU ready to play Rock-Paper-Scissors-Lizard-Spock? \n");
    	printf("0 for NO \n1 for YES ");
    	scanf("%d", &ready);
    
    	while (ready == 1 && retry == 1)
    	{
    
    		printf("Player One!! ENTER YOUR CHOICE \n1 = Rock \n2 = Paper \n3 = Scissors \n4 = Lizard \n5 = Spock \n");
    		scanf("%d", &player_One_Choice);
    
    
    		printf("Player Two!! ENTER YOUR CHOICE \n1 = Rock \n2 = Paper \n3 = Scissors \n4 = Lizard \n5 = Spock \n");
    		scanf("%d", &player_Two_Choice);
    
    
    		if (player_One_Choice == 1 && player_Two_Choice == 1 || player_One_Choice == 2 && player_Two_Choice == 2 || player_One_Choice == 3 && player_Two_Choice == 3 || player_One_Choice == 4 && player_Two_Choice == 4 || player_One_Choice == 5 && player_Two_Choice == 5)
    		{
    			printf("\nPlayer 1 selected: %d\n", player_One_Choice);
    			printf("\nPlayer 2 selected: %d\n", player_Two_Choice);
    			printf("\nYou tied, we cant end things like this, TRY AGAIN!!!???\n0 for NO \n1 for YES \n");
    		}
    		if (player_One_Choice == 1 && player_Two_Choice == 4 || player_One_Choice == 1 && player_Two_Choice == 3 || player_One_Choice == 2 && player_Two_Choice == 1 || player_One_Choice == 2 && player_Two_Choice == 5 || player_One_Choice == 3 && player_Two_Choice == 2 || player_One_Choice == 3 && player_Two_Choice == 4 || player_One_Choice == 4 && player_Two_Choice == 5 || player_One_Choice == 4 && player_Two_Choice == 2 || player_One_Choice == 5 && player_Two_Choice == 3 || player_One_Choice == 5 && player_Two_Choice == 1)
    		{
    			printf("\nPlayer 1 selected: %d\n", player_One_Choice);
    			printf("\nPlayer 2 selected: %d\n", player_Two_Choice);
    			printf("\nPlayer 1, victory!, TRY AGAIN???\n0 for NO \n1 for YES \n");
    		}
    		if (player_One_Choice == 4 && player_Two_Choice == 1 || player_One_Choice == 3 && player_Two_Choice == 1 || player_One_Choice == 1 && player_Two_Choice == 2 || player_One_Choice == 5 && player_Two_Choice == 2 || player_One_Choice == 2 && player_Two_Choice == 3 || player_One_Choice == 4 && player_Two_Choice == 3 || player_One_Choice == 5 && player_Two_Choice == 4 || player_One_Choice == 2 && player_Two_Choice == 4 || player_One_Choice == 3 && player_Two_Choice == 5 || player_One_Choice == 1 && player_Two_Choice == 5)
    		{
    			printf("\nPlayer 1 selected: %d\n", player_One_Choice);
    			printf("\nPlayer 2 selected: %d\n", player_Two_Choice);
    			printf("\nPlayer 2, victory!, TRY AGAIN???\n 0 for NO \n1 for YES \n");
    		}
    		scanf("%d", &retry);
    	}
    	return 0;
    }
    But why do it that way when you can just use the 'Ready' variable and keep it simple.

  11. #11
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Your variable names are tooooooo_looooong!

    Testing for a tie is simpler than you make it. Why not just
    Code:
    if (choice1 == choice2) {
        // tie
    }
    Actually, testing for a win is easier, too, if you look at this pattern:
    rock, spock, paper, lizard, scissors
    Note that each thing beats the two to its left, with wrap-around.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rock Paper Scissors Program Help
    By Sep1256 in forum C Programming
    Replies: 7
    Last Post: 11-23-2010, 01:51 PM
  2. paper rock scissors
    By Amyaayaa in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2008, 10:59 AM
  3. need help with rock paper scissors program
    By Mshock in forum C Programming
    Replies: 3
    Last Post: 04-22-2006, 07:44 AM
  4. Rock, Paper, Scissors
    By Twiggy in forum C Programming
    Replies: 9
    Last Post: 11-06-2001, 05:06 AM

Tags for this Thread