-
Notifications
You must be signed in to change notification settings - Fork 0
/
RussianRoulette.c
63 lines (59 loc) · 1.33 KB
/
RussianRoulette.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
58
59
60
61
62
63
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
int randomNum(int n){
srand(time(NULL));
return rand()%n;
}
int shoot(char p[],int *n, int* num){
char choice;
printf("%s type y to shoot yourself: ",p);
scanf(" %c",&choice);
if (choice=='y'){
if ((*num)==(*n)){
printf("%s Died\n",p);
return 1;
}
else{
(*num)++;
printf("%s lived\n",p);
return 0;
}
}
else{
if ((*num)==(*n)){
printf("%s Died\n",p);
return 1;
}
else {
(*num)++;
printf("%s lived\n",p);
return 0;
}
}
}
void play (char Players[2][100]){
int n =randomNum(6)+1;
int num=1;
int p1_dead=0;
int p2_dead=0;
for(int i=0;i<6;i++){
p1_dead=shoot(Players[0],&n,&num);
if (p1_dead) break;
p2_dead=shoot(Players[1],&n,&num);
if (p2_dead) break;
}
}
int main(){
char Players[2][100];
printf("Welcome to Russian Roullete. Its a 2 Player Game.\n");
printf("Player 1 will be the first one to try!\n");
printf("Enter name of Player 1\n");
scanf("%s",Players[0]);
printf("Enter name of Player 2\n");
scanf("%s",Players[1]);
play (Players);
return 0;
}