-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRPScLSp_Final.c
More file actions
164 lines (159 loc) · 4.16 KB
/
Copy pathRPScLSp_Final.c
File metadata and controls
164 lines (159 loc) · 4.16 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
//Author Ethan Chong
int Upoints = 0;
int Cpoints = 0;
char game;
char symbols[50];
void Rock(char game){
if (game == 3){
printf("You win, Rock beats Scissors\n");
Upoints++;
}
else if (game == 4){
printf("You win, Rock beats Lizard\n");
Upoints++;
}
else if (game == 2){
printf("You lose, Paper beats Rock\n");
Cpoints++;
}
else if (game == 5){
printf("You lose, Spock beats Rock\n");
Cpoints++;
}
else if (game == 1){
printf("Draw same as the Program\n");
}
}
void Paper(char game){
if (game == 1){
printf("You win, Paper beats Rock\n");
Upoints++;
}
else if (game == 5){
printf("You Win, Paper beats Spock\n");
Upoints++;
}
else if (game == 4){
printf("You lose, Lizard beat paper\n");
Cpoints++;
}
else if (game == 3){
printf("You lose, Scissors beats paper\n");
Cpoints++;
}
else if (game == 2){
printf("Draw same as the Program\n");
}
}
void Scissors(char game){
if (game == 4){
printf("You win, Scissors beats Lizard\n");
Upoints++;
}
else if (game == 2){
printf("You win, Scissors beats Paper\n");
Upoints++;
}
else if (game == 1){
printf("You lose, Rock beats Scissors\n");
Cpoints++;
}
else if (game == 5){
printf("You lose, Spock beats Scissors\n");
Cpoints++;
}
else if (game == 3){
printf("Draw same as the Program\n");
}
}
void Lizard(char game){
if (game == 2){
printf("You win, Lizard beats Paper\n");
Upoints++;
}
else if (game == 5){
printf("You win, Lizard beats Spock\n");
Upoints++;
}
else if (game == 1){
printf("You lose, Rock beats Lizard\n");
Cpoints++;
}
else if (game == 3){
printf("You lose, Scissors beats Lizard\n");
Cpoints++;
}
else if (game == 4){
printf("Draw same as the Program\n");
}
}
void Spock(char game){
if (game == 1){
printf("You win, Spock beats Rock\n");
Upoints++;
}
else if (game == 3){
printf("You win, Spock beats Scissors\n");
Upoints++;
}
else if (game == 4){
printf("You lose, Lizard beats Spock\n");
Cpoints++;
}
else if (game == 2){
printf("You lose, Paper beats Spock\n");
Cpoints++;
}
else if (game == 5){
printf("Draw same as the Program\n");
}
}
int main(){
int numberOfTrials=0; //number of Trials
srand(time(0));
printf("Lets play Rock, Paper, Scissors...\nLizard, SPOCK!!!\n");
printf("Enter the number of trials:\n");
scanf("%d",&numberOfTrials);
printf("Enter Rock, Paper, Scissors, Lizard, Spock\n");
for (int i = 0; i < numberOfTrials; i++){
game=rand()%5+1;
printf("Enter your choice:\n");
scanf("%s",&symbols);
//Rock operation
if (strcmp(symbols, "Rock")==0){
Rock(game);
}
//Paper operation
if (strcmp(symbols, "Paper")==0){
Paper(game);
}
//Scissors operation
if (strcmp(symbols, "Scissors")==0){
Scissors(game);
}
//Lizard operation
if (strcmp(symbols, "Lizard")==0){
Lizard(game);
}
//Spock operation
if (strcmp(symbols, "Spock")==0){
Spock(game);
}
}
if(Cpoints > Upoints){
int Cdiff = Cpoints - Upoints;
printf("The Program wins %d and you got %d\n. You only needed %d points\n",Cpoints,Upoints,Cdiff);
}
else if(Upoints > Cpoints){
int Udiff = Upoints - Cpoints;
printf("User wins %d. The Program had %d points. It was only %d points away\n",Upoints,Cpoints,Udiff);
}
else if(Cpoints = Upoints){
printf("No one wins! You got %d. Better luck next time :)\n",Upoints);
}
return 0;
}