Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions snake_water_gun_project.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
int snakeWaterGun(char you, char comp)
{
if (you == comp)
{
return 0;
}
if (you == 's' && comp == 'g')
{
return -1;
}
else if (you == 'g' && comp == 's')
{
return 1;
}
if (you == 'w' && comp == 's')
{
return -1;
}
else if (you == 's' && comp == 'w')
{
return 1;
}
if (you = 'g' && comp == 'w')
{
return -1;
}
else if (you == 'w' && comp == 'g')
{
return 1;
}
}
int main()
{
char you, comp;
srand(time(0));
int number = rand()%100 + 1;
if (number < 33)
{
comp = 's';
}
else if(number > 33 && number < 66)
{
comp = 'w';
}
else
{
comp = 'g';
}

printf("Enter 's' for snake, 'w' for water, 'g' for gun\n");
scanf("%c",&you);
int result = snakeWaterGun(you, comp);

if (result == 0)
{
printf("Game Draw !!!\n");
}
else if (result == 1)
{
printf("You win !!!\n");
}
else
{
printf("You loose !!!\n");
}
printf("You have chosen %c and Computer has chosen %c...\n",you, comp);

return 0;
}