Begginers Program

This is a discussion on Begginers Program within the C Programming forums, part of the General Programming Boards category; Hey guys. Im just a begginer Here can you please help me . I am trying to make a program ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    8

    Unhappy Begginers Program

    Hey guys. Im just a begginer Here can you please help me . I am trying to make a program that will play the famous game Paper, Rock , Scissor . And i found some problems here and i cant undestand. Can you please give me some idea how can i correct my mistakes and enchance my program .



    Name:  hard.jpg
Views: 260
Size:  70.7 KB

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    5,852
    Yikes.

    Find any basic text on C, and read the first few chapters before touching your keyboard again.

    If you want Scissor to have a value zero, then the syntax (to define and initialise) is
    Code:
        int Scissor = 0;
    you can't just swap parts of that thing around. Variable name to the left of the equal sign, value to the right.

    A value of zero in the scanf() call does not somehow map to "Scissor".
    You probably intend something like
    Code:
       scanf("%c", &Player_1);
    (%c is used to read a character, the &Player_1 means the variable Player_1 receives the value of the character read). Don't use %d to read a character, or %c to read an int. They don't mix.
    Right 98% of the time, and don't care about the other 3%.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171
    This is C, not C++, so why did you post it on the C++ board?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    8
    Sorry ely , i was begginer . Bdw. Do you play COg ely . Your name looks familiar.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171
    No, I don't play it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  6. #6
    Registered User
    Join Date
    Oct 2012
    Posts
    8
    can anyone pleas help . How can i ramdomly generate the computer answer.

    Code:
    /*
    	
    */
    
    #include<stdio.h>
    int main ()
    {
    
    	/*Local Declarations*/
    	
    	char Player1;
    	char Player2;
    	int S;
    	int R;
    	int P;
    	
    	/*Statements*/
    	
    	printf("Hello Everybody I assume that you know how to play this Game\n");
    	printf("\n");
    	printf("Ok! Guys Lets Start !!");
    	printf("\n");
    	printf("Instructions:\n");
    	printf("\n");
    	printf("If you want to choose Scissor, Type the Capital letter (S)\n");
    	printf("\n");
    	printf("Next , If you want to choose Rock, Type the Capital letter (R)\n");
    	printf("\n");
    	printf("And Last If you want to pick Paper, Type the Capital letter (P)\n");
    	printf("\n");
    	printf("Choose your Weapon:");
    	scanf("%d%d%d", S, R, P );
    	if(Player1='S')
    	{
    		printf("You choose Scissor");
    	}
    	else if (Player1='R')
    	{
    		printf("You Choose Rock");
    	}
    	else if (Player1='P')
    	{
    		printf("You Choose Paper");
    	}
    	else 
    	{
    		printf("Dont try to confuse me, You Cheater :P");
    	}
    	return 0;
    	
    	if (Player2='S')
    	{
    		printf("Computer choose Scissor");
    	}
    	else if (Player2='R')
    	{
    		printf("Computer choose Rock");
    	}
    	else if (Player2='P')
    	{
    		printf("Computer choose Paper");
    	}
    	else
    	{
    		printf("Dont confuse me");
    	}
    	
    	if (Player1=Player2)
    	{
    		printf("You Tied");
    	}
    	if (Player1='S')
    	{
    	if (Player2='P')
    	{
    		printf("Player1 Wins the Game");
    	}
    	else if (Player2='R')
    	{
    		printf("Player2 Wins the Game");
    	}
    
    	return 0;
    }
    }

  7. #7
    Registered User
    Join Date
    Oct 2012
    Posts
    8

    I need some Little help here (Begginer on C).

    can anyone pleas help . How can i ramdomly generate the computer answer and it keeps choosing scissor !!

    Code:
    /*
        
    */
    
    #include<stdio.h>
    int main ()
    {
    
        /*Local Declarations*/
        
        char Player1;
        char Player2;
        int S;
        int R;
        int P;
        
        /*Statements*/
        
        printf("Hello Everybody I assume that you know how to play this Game\n");
        printf("\n");
        printf("Ok! Guys Lets Start !!");
        printf("\n");
        printf("Instructions:\n");
        printf("\n");
        printf("If you want to choose Scissor, Type the Capital letter (S)\n");
        printf("\n");
        printf("Next , If you want to choose Rock, Type the Capital letter (R)\n");
        printf("\n");
        printf("And Last If you want to pick Paper, Type the Capital letter (P)\n");
        printf("\n");
        printf("Choose your Weapon:");
        scanf("%d%d%d", S, R, P );
        if(Player1='S')
        {
            printf("You choose Scissor");
        }
        else if (Player1='R')
        {
            printf("You Choose Rock");
        }
        else if (Player1='P')
        {
            printf("You Choose Paper");
        }
        else 
        {
            printf("Dont try to confuse me, You Cheater :P");
        }
        return 0;
        
        if (Player2='S')
        {
            printf("Computer choose Scissor");
        }
        else if (Player2='R')
        {
            printf("Computer choose Rock");
        }
        else if (Player2='P')
        {
            printf("Computer choose Paper");
        }
        else
        {
            printf("Dont confuse me");
        }
        
        if (Player1=Player2)
        {
            printf("You Tied");
        }
        if (Player1='S')
        {
        if (Player2='P')
        {
            printf("Player1 Wins the Game");
        }
        else if (Player2='R')
        {
            printf("Player2 Wins the Game");
        }
    
        return 0;
    }
    }
    Last edited by Bat Ako; 10-06-2012 at 08:53 AM.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This is not what you want:
    Code:
    scanf("%d%d%d", S, R, P );
    1st: you are asking for three entries, instead of just ONE of those three choices.

    2nd: you need the ADDRESS OF the variable, so scanf() can change it. Add the & in front of the variables name: &S for instance.

    3rd: to get a random answer is a bit more difficult. Are you trying to have the computer play against itself, or is it playing against 1 human, or is it playing against two humans, or is it not playing, but serving as a referee, for three humans, while they play?

  9. #9
    Registered User
    Join Date
    Oct 2012
    Posts
    8
    uhm. i trying to make a program that will play the game paper , scissor , rock . Player 1 is the Human and the Player 2 is the computer. If the Player choose S or P or R. The Player will automatically and randomly generates his answer.

  10. #10
    Registered User
    Join Date
    Jun 2005
    Posts
    5,852
    Yeah, but you need to express that way in a manner the computer (or the C compiler) can understand. C compilers do not accept hand-wavy descriptions. They certainly don't have any context to know what a game is, let alone paper, scissor, rock.

    The previous posts are about some of the specifics of describing your problem in a way that a C compiler can understand. Imagine you are communicating with a pedantic ignoramus that will only do what you want if you describe your problem in EXACTLY the way it can understand. That ignoramus cannot change how it communicates to suit you. You must change how your communicate to suit it. However, once you do, that ignoramus will do exactly what you want, faithfully, and repeatedly if needed. If you get the communication wrong, the ignoramus will either complain bitterly (if it can't make sense of what you tell it) or it will do something other than what you expect.

    The C compiler is that pedantic ignoramus. The C code is the means by which you communicate with it. The preceding posts are about the mistakes you have made in communicating with the ignoramus. If you are not willing to act on that advice, and change how you communicate so the compiler can understand, then you have no business trying to program in C.
    Right 98% of the time, and don't care about the other 3%.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ideal IDE for C Prog - For Begginers
    By Anitrex in forum C Programming
    Replies: 19
    Last Post: 12-23-2011, 12:29 PM
  2. Nested Loops for begginers
    By jason007thomas in forum C++ Programming
    Replies: 11
    Last Post: 11-19-2011, 07:58 PM
  3. Replies: 1
    Last Post: 03-03-2009, 03:47 PM
  4. c begginers
    By nksprakash in forum C Programming
    Replies: 4
    Last Post: 05-31-2007, 12:13 PM
  5. begginers if statement problem
    By lastresort in forum C++ Programming
    Replies: 3
    Last Post: 01-31-2005, 03:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21