ROCK PAPER SCISSORS GAME
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void choice(char you,char me)
{
if(you==me)
{
printf("GAME DRAW!\n");
}
else if(you=='r' && me=='p')
{
printf("YOU LOST!\n");
}
else if(you=='r' && me=='s')
{
printf("YOU WON!\n");
}
else if(you=='p' && me=='r')
{
printf("YOU WON!\n");
}
else if(you=='p' && me=='s')
{
printf("YOU WON!\n");
}
else if(you=='s' && me=='p')
{
printf("YOU WON!\n");
}
else if(you=='s' && me=='r')
{
printf("YOU LOST!\n");
}
}
int main()
{
char you,me;
printf("enter your choice:('r'for rock,'p'for paper,'s'for scissors):");
scanf("%c",&you);
int n;
srand(time(0));
n=rand()%100;
if(n<30)
{
me='r';
}
else if(n>30 && n<60)
{
me='p';
}
else
{
me='s';
}
choice(you,me);
printf("you've chosen %c and i've choosen %c\n",you,me);
}
Comments
Post a Comment