creating snake , water , gun game in c

 #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=='s' && comp=='w'){

return  1;

}

else if(you=='w' && comp=='s'){

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 if(number<66){

  comp = 'g';

  }

  

  

  printf("Enter 's' for snake , 'g' for gun , 'w' for water\n");

  scanf("%c",&you);

    int result =  SnakeWaterGun(you ,comp);

  printf("You chose %c and comp chose %c ",you , comp);

  if(result ==0){

  printf("Game draw!\n");

  }

  else if(result == 1){

  printf("you Win!\n");

  }

  else{

  printf("you Lose!\n");

  }

  return 0; 

}


Comments

Popular posts from this blog

create a num table in a new file in c

write a programme to compare time stamp in c

write a struct programme to keep bank details in c