Advertisement
Guest User

carta_forbice_sasso_lizard_spock

a guest
Mar 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. void main(void)
  5.  {
  6.   int computer,scelta;
  7.  
  8.  
  9.   printf("Scegli la tua mossa:\n");
  10.   printf("0) sasso\n1) carta \n2) forbice\n3) lizard\n4) Spock\n");
  11.   scanf("%d",&scelta);
  12.  
  13.   if ((scelta>=5)||(scelta<0))
  14.    {printf("Non hai selezionato nessuna mossa\n");}
  15.   else
  16.   {
  17.    printf("Hai scelto: \n%d\n",scelta);
  18.    srand(time(NULL));
  19.    computer=rand() %5;
  20.    printf("Il computer ha scelto: \n%d\n",computer);
  21.  
  22.    if
  23.      ((scelta==0&&computer==2)||(scelta==0&&computer==3)||
  24.       (scelta==1&&computer==0)||(scelta==1&&computer==4)||
  25.       (scelta==2&&computer==1)||(scelta==2&&computer==3)||
  26.       (scelta==3&&computer==4)||(scelta==3&&computer==1)||
  27.       (scelta==4&&computer==2)||(scelta==4&&computer==0))
  28.     {
  29.      printf("Hai vinto!\n");
  30.     }
  31.    else
  32.     {
  33.      if(scelta==computer)
  34.       {printf("Hai pareggiato\n");}
  35.      else
  36.       {printf("Hai perso\n");}
  37.     }
  38.   }
  39.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement