#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    74
    Rep Power
    2

    I need help about FUNCTION


    here is my screen output:


    How am i gonna put them together? i mean side to side and not underneath of the other

    here is my code:

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    void paper()
    {
    	printf("      _____\n");
    	printf("     /     \\\n");
    	printf("    /   ___/_________\n");
    	printf(" __/                 \\\n");
    	printf("|           |________/____\n");
    	printf("|                         \\\n");
    	printf("|           |_____________/\n");
    	printf("|                       \\\n");
    	printf("|           |___________/\n");
    	printf("|                   \\\n");
    	printf("|_          |_______/\n");
    	printf("  \\________/\n");
    }
    
    void rock()
    {
    	printf("      _____\n");
    	printf("     /     \\_______\n");
    	printf("    /       \\      |\n");
    	printf(" __/         \\_____|\n");
    	printf("|        \\   |     |\n");
    	printf("|         \\__|_____|\n");
    	printf("|           |      |\n");
    	printf("|           |______|\n");
    	printf("|           |      |\n");
    	printf("|_          |______|\n");
    	printf("  \\__________/\n");
    }
    
    void scissor()
    {
    	printf("      ___________________\n");
    	printf("     /     \\             \\\n");
    	printf("    /       \\    ________/\n");
    	printf(" __/         \\  |___________\n");
    	printf("|         \\   \\             \\\n");
    	printf("|        __\\  |_|___________/\n");
    	printf("|       /   \\_| \\\n");
    	printf("|       \\_______/\n");
    	printf("|        /     \\\n");
    	printf("|_       \\_____/\n");
    	printf("  \\__________/\n");
    }
    
    main()
    {
    	char p[2];
          
          printf("\t\t\t\tJACK EN POY");
          printf("\n\nBET OPTIONS");
          printf("\n\n[S or s] = SCISSOR\n[P or p] = PAPER\n[R or r] = ROCK");
          printf("\n\n\n\t\tPLAYER ONE's BET: ");
          scanf("%s", &p[0]);
          system("cls");
          printf("\t\t\t\tJACK EN POY");
          printf("\n\nBET OPTIONS");
          printf("\n\n[S or s] = SCISSOR\n[P or p] = PAPER\n[R or r] = ROCK");
          printf("\n\n\n\t\tPLAYER ONE's BET: ?");
          printf("\t\tPLAYER TWO's BET: ");
          scanf("%s", &p[1]);
          system("cls");
                        
                        
                        
          //PAPER-ROCK CONDITION              
          if((p[0]=='P' || p[0]=='p') && (p[1]=='R' || p[1]=='r'))
    	  {
    	  	printf("\t\t\t PLAYER ONE WINS! CONGRATULATIONS!\n");
    		paper(); rock();
    	  }
          
    	  else if((p[0]=='R' || p[0]=='r') && (p[1]=='P' || p[1]=='p'))
    	  {
    	  	printf("\t\t\t PLAYER TWO WINS! CONGRATULATIONS!\n");
    	  	rock(); scissor();
    	  }
    	  
                           
                           
          //SCISSOR-PAPER CONDITION                 
          else if((p[0]=='S' || p[0]=='s') && (p[1]=='P' || p[1]=='p'))
          {
          	printf("\t\t\t PLAYER ONE WINS!CONGRATULATIONS!\n");
          	scissor(); paper();
          }
          
    	  else if((p[0]=='P' || p[0]=='p') && (p[1]=='S' || p[1]=='s'))
    	  {
    	  	printf("\t\t\t PLAYER TWO WINS!CONGRATULATIONS!\n");
    	  	paper(); scissor();
    	  }
          
                                                 
          //ROCK-SCISSOR CONDITION                    
          else if((p[0]=='R' || p[0]=='r') && (p[1]=='S' || p[1]=='s'))
          {
          	printf("\t\t\t PLAYER ONE WINS! CONGRATULATIONS!\n");
          	rock(); scissor();
          }
           
          
    	  else if((p[0]=='S' || p[0]=='s') && (p[1]=='R' || p[1]=='r'))
    	  {
    	  	printf("\t\t PLAYER TWO WINS! CONGRATULATIONS!\n");
    	  	scissor(); rock();
    	  }
          
                                                  
          /*condtion 4 if input is invalid or the same user input*/
          else if((p[0]=='R' || p[0]=='r') && (p[1]=='R' || p[1]=='r'))
          {
          	printf("\t\t\t\t  IT's A DRAW\n");
          	rock(); rock();
          }
          
          else if((p[0]=='S' || p[0]=='s') && (p[1]=='S' || p[1]=='s'))
          {
          	printf("\t\t\t\t  IT's A DRAW\n");
          	scissor(); scissor();
          }
          
          else if((p[0]=='P' || p[0]=='p') && (p[1]=='P' || p[1]=='p'))
          {
          	printf("\t\t\t\t  IT's A DRAW\n");
          	paper(); paper();
          }
          
          else
          printf("\n\n\n\t\t\t      ERROR: INVALID INPUT");
          getch();
          return 0;
    }
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    Do something like
    Code:
    char *paper[] = {
       "      _____",
       "     /     \\",
       "    /   ___/_________",
       " __/                 \\",
       "|           |________/____",
       "|                         \\",
       "|           |_____________/",
       "|                       \\",
       "|           |___________/",
       "|                   \\",
       "|_          |_______/",
       "  \\________/",
    };
    char *rock[] = {
       "      _____",
       "     /     \\_______",
       "    /       \\      |",
       " __/         \\_____|",
       "|        \\   |     |",
       "|         \\__|_____|",
       "|           |      |",
       "|           |______|",
       "|           |      |",
       "|_          |______|",
       "  \\__________/",
    };
    Then in a loop, you can do
    printf("%40s%s\n", paper[i], rock[i] );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    74
    Rep Power
    2
    Originally Posted by salem
    Do something like
    Code:
    char *paper[] = {
       "      _____",
       "     /     \\",
       "    /   ___/_________",
       " __/                 \\",
       "|           |________/____",
       "|                         \\",
       "|           |_____________/",
       "|                       \\",
       "|           |___________/",
       "|                   \\",
       "|_          |_______/",
       "  \\________/",
    };
    char *rock[] = {
       "      _____",
       "     /     \\_______",
       "    /       \\      |",
       " __/         \\_____|",
       "|        \\   |     |",
       "|         \\__|_____|",
       "|           |      |",
       "|           |______|",
       "|           |      |",
       "|_          |______|",
       "  \\__________/",
    };
    Then in a loop, you can do
    printf("%40s%s\n", paper[i], rock[i] );

    THANK YOU! =)
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    74
    Rep Power
    2
    any other solution? i couldnt let it work >_>
  8. #5
  9. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    How about posting what you managed to achieve.

    Then we can fix it.

    > any other solution? i couldnt let it work >_>
    Yes, the way I showed you, but implemented without the bugs you've put in.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    74
    Rep Power
    2
    i did it something like this

    Code:
    char paper(char x)
    {
          char *paper[]= {
            printf("      _____\n");
    	printf("     /     \\\n");
    	printf("    /   ___/_________\n");
    	printf(" __/                 \\\n");
    	printf("|           |________/____\n");
    	printf("|                         \\\n");
    	printf("|           |_____________/\n");
    	printf("|                       \\\n");
    	printf("|           |___________/\n");
    	printf("|                   \\\n");
    	printf("|_          |_______/\n");
    	printf("  \\________/\n");
        };
    }
    i feel that your solution is correct,perhaps i just dont know how to do it >_> kind of new in fucntions.
  12. #7
  13. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    I said to put the strings in the arrays, not put the printf's in the arrays.

    Then it's something like
    Code:
    void doPrint ( char *left[], char *right[] ) {
        printf("%40s%s\n", left[0], right[0] );  // except you make this a loop!
    }
    And you call it with
    doPrint(rock,paper);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  14. #8
  15. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    Now that salem has explained the same thing to you for a second time, look at what he wrote, look at what you did, pay particular attention to how they differ.

    Comments on this post

    • Kamikageyami agrees
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    74
    Rep Power
    2
    i have not learned bout POINTERS yet, and we are only allowed to use functions. i really dont have an idea, what you had explained Salem

    but thank you BIG TIME! you bothered to answer my query
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    19
    Rep Power
    0
    The problem isn't with pointers, you're trying to store the printf's inside your array.

IMN logo majestic logo threadwatch logo seochat tools logo