Thread: Make a simple C Program

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    15

    Make a simple C Program

    Make a C Program.
    Can someone help me with this. My teacher ask me to do this to make me pass the midterm. Please help me guys. Thanks in advance those who can help.

    Write a "scissors-rock-paper" game, commonly known as "jack n poy" in the Philippines. Two players will input the first equivalent letter. For example, S for scissors, R for rock, and P for paper. Then display the winner and the basis of winning such as: "paper covers rock", "rock breaks scissors", and "scissors cut paper", or "nobody wins". Capital or small letters should be accepted by your program.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Sure. In the meantime, could [you] clean my house whenever I need it cleaned?

    Edit: sorry, missed the "you" there.
    Last edited by EVOEx; 09-02-2009 at 04:18 AM.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    15
    Ok Thanks.

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    gamit ka ng rand()

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You need to make an effort. Ask specific questions and you'll get help. But nobody is going to write the program for you.
    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.

  6. #6
    Registered User
    Join Date
    Aug 2009
    Posts
    58
    If you think about this there is not too much for it.

    You need to take in char type from each user.
    Create an if statement to do the compare
    Print your result!!


    Load of examples of this on the web, just write it down on paper and think about it in small bits and not a big project.

    Also take deep breaths and stop panicking!!

  7. #7
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    By the time the prof is asking you to write this you should be able to do it with no problems if you paid attention in class, and if not, then we really don't need more sliders in the IT field, we already have enough of them as is.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Often, it is a specific thing they do not understand, but they don't know better than just dumping it all here and expecting us to help them.
    Many professors are just plain dumb and don't explain things well enough to students, either, so don't go blaming the professor or the student without more proof of where the actual problem lies.
    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.

  9. #9
    Registered User
    Join Date
    Aug 2009
    Posts
    15
    i dont know how to code when it comes to the input of the two user and who will win..

    #include <stdio.h>

    void main()

    {
    char x;
    printf("Please enter your letter: ");
    scanf("%c", &x);

    wats next?

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > My teacher ask me to do this to make me pass the midterm.
    What have you been doing for half a term that you can't even make a program that will compile.

    > wats next?
    Well let's say that x is the rock/paper/scissors for player 1
    How about the same for player 2?

    Then use the game logic?
    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.

  11. #11
    Registered User
    Join Date
    Aug 2009
    Posts
    58
    When you asked the second user for their input, think about how do you compare the two inputs.

    If any doubt on the compare look up switch statements, if statements, loops.

    These are things you will always use in c, so getting to know them now is vital!

  12. #12
    Registered User
    Join Date
    Aug 2009
    Posts
    15
    #include <stdio.h>

    void main()

    {
    char x, y;
    printf("Player 1 please enter your letter: ");
    scanf("%c", &x);
    printf("Player 2 please enter your letter: ");
    scanf("%c", &y);

    this is where im stuck.

  13. #13
    Registered User
    Join Date
    Aug 2009
    Posts
    58
    Read my post above.
    Ask yourself what you need to do next logical before programming and look up what i said above.

  14. #14
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    First, use code tags around your program:

    Highlight your program, then click on the '#' icon on the forum composition window.

    Second, all C program should have int main(void) at least, with a return of zero at the end for normal exiting.

    Third, consider using some if statements to work out your logic for rock, paper, scissors. A pad and pencil is sometimes the best way to do that, instead of just trying to code it, straightaway.

  15. #15
    Registered User
    Join Date
    Aug 2009
    Posts
    15
    Heres my simple code.

    But nothing displays on the screen who wins the match of the game.

    Can someone help me how to make the program execute from the first again after displaying the match results and press Enter?

    Code:
    #include <stdio.h>
    
    
    int main()
    
    {
        int user_choice1;
        int user_choice2;
        printf("This is a rock, paper, and scissor game. \nPlease select 1 for Rock, 2 for Paper, and 3 for Scissors.");
        printf("\nPlayer One's Choice: ");
        scanf("%d", &user_choice1);
        printf("\nPlayer Two's Choice: ");
        scanf("%d", &user_choice2);
        
        {
        
        if ((user_choice1==1)&&(user_choice2==1))
          {
            printf("\nNobody Wins");
          }
        else if ((user_choice1==1)&&(user_choice2==2))
          { printf("\nPaper Covers Rock");
          }
        else if ((user_choice1==1)&&(user_choice2==3))
          { printf("\nRock Breaks Scissors");
          }
        else if((user_choice1==2)&&(user_choice2==1))
          { printf("\nPaper Covers Rock");
          }
        else if((user_choice1==2)&&(user_choice2==2))
          { printf("\nNobody Wins");
          }
        else if((user_choice1==2)&&(user_choice2==3))
          { printf("\nScissors Cuts Paper");
          }
        else if((user_choice1==3)&&(user_choice2==1))
          { printf("\nRock Breaks Scissors");
          }
        else if((user_choice1==3)&&(user_choice2==2))
          { printf("\nScissors Cuts Paper");
          }
        else if((user_choice1==3)&&(user_choice2==3))
          { printf("\nNobody Wins");
          }
        else
          { printf("You have select an invalid selection.");
          
          }
     
       
       }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple window program
    By baniakjr in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2006, 03:46 PM
  2. want to make this small program...
    By psycho88 in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2005, 02:05 AM
  3. Help with small simple program
    By Sonor in forum C Programming
    Replies: 5
    Last Post: 04-02-2005, 07:40 AM
  4. Replies: 1
    Last Post: 03-12-2002, 06:31 AM
  5. Trying to make rand different per program run
    By Dreamerv3 in forum C++ Programming
    Replies: 6
    Last Post: 01-18-2002, 03:26 AM