-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_02.c
57 lines (55 loc) · 1.14 KB
/
game_02.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int stonepaperscissor(char me, char computer){
// conditions for draw
if(computer == me)
return 0;
if(me=='s' && computer =='p'){
return -1;
}
else if(me=='p' && computer =='s'){
return 1;
}
if(me=='c' && computer =='p'){
return 1;
}
else if(me=='p' && computer =='c'){
return -1;
}
if(me=='s' && computer =='s'){
return 1;
}
else if(me=='s' && computer =='s'){
return -1;
}
}
int main(){
char me, computer;
srand(time(0));
int number=rand()%10+1;
if(number<3){
computer = 's';
}
else if(number>3 && number<6){
computer = 'p';
}
else{
computer = 'c';
}
printf("Enter s for stone p for paper and c for scissor\n");
scanf("%c", &me);
int result = stonepaperscissor(me,computer);
if(result==1){
printf("You Win\n");
}
else if(result==0){
printf("Draw\n");
}
else{
printf("You Lose\n");
}
printf("*********\n");
printf("\n\nYou had chosen %c and computer had chosen %c", me, computer);
return 0;
}