Thread: Need a Little Help Here .

  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?

    Need a Little Help Here .-dssss-jpg

    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  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);
    Need a Little Help Here .-saw-jpg

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    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,815
    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 or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed