Need a Little Help Here .

This is a discussion on Need a Little Help Here . within the C Programming forums, part of the General Programming Boards category; uhm , Guys can anyone help me and tell me what is wrong in my program? Code: #include<stdio.h> int main() ...

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

    Post Need a Little Help Here .

    uhm , Guys can anyone help me and tell me what is wrong in my program?

    Name:  dssss.jpg
Views: 112
Size:  72.5 KB

    Code:
    #include<stdio.h>
    int main()
    {
    
        int userSel;
        int compSel = (rand() % 3) + 1;
        int count1;
        int x=0;
        int y=1;
        int z=2;
        
        
        
        printf("Welcome to >>>Rock Paper Scissors<<<\n");
        printf("");
        printf(" So lets begin. You are playing against the computer\n");
        printf("");
        printf("Type 0 for rock, 1 for paper,and 2 for scissors\n");
        
     if (userSel==0)
     {
        printf("You chose Rock.");
     }
     else if (userSel==1)
     {
        printf("You chose Paper.");
     }
     else if (userSel==2)
     {
        printf("You chose scissors.");
     }
     else
     {
        printf("Invalid choice.");
      return 1;
     }
      
     if (compSel==0)
     {
         printf("Computer chose rock.");
     }
     else if (compSel==1)
     {    
        printf("Computer chose paper.");
     }
     else if (compSel==2)
     {
        printf("Computer chose scissors.");
     }
      
        count1++;
     
     if (userSel==compSel)
     {
        printf("You Tie");
     }
     if (userSel==0)
     {
      if (compSel=1)
      {
       printf("You lose");
      }
      else if (compSel=2)
      {
        printf("You win");
      }
     }
     else if (userSel==1)
     {
      if (compSel==0)
      {
        printf("You win");
      }
      else if (compSel==2)
      {
        printf("You lose");
      }
     }
     else if (userSel==2)
     {
      if (compSel==1)
      {
        printf("You lose");
      }
      else if (compSel==1)
      {
        printf("You lose");
      }
     }
       
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,751
    Where is your call to scanf(), or any other input function, to allow you to make a choice?
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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

    Reply :D

    Quote Originally Posted by Salem View Post
    Where is your call to scanf(), or any other input function, to allow you to make a choice?
    i tried but . and when i put the scanf thing ...

    Code:
    scanf("%d%d%d", &x, &y, &z);
    Name:  saw.jpg
Views: 79
Size:  83.9 KB

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    Lines 59 and 63 need to use comparison '==', not assignment '='.
    Line 81 should compare with 0.
    Line 87 should be "win".

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,528
    Quote Originally Posted by Bat Ako View Post
    and when i put the scanf thing ...
    Code:
    scanf("%d%d%d", &x, &y, &z);
    This scanf() call reads values into variables x, y, and z.

    The rest of your code doesn't do anything with x, y, or z. It does do stuff based on value of a variable named UserSel, but the scanf() call does not read any value into UserSel.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy in reply to you, it is likely you deserve it. Suck it up, sunshine, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

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