-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeCom.c
More file actions
55 lines (54 loc) · 1.66 KB
/
codeCom.c
File metadata and controls
55 lines (54 loc) · 1.66 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
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
char a,b,g=0,h=0;
srand(time(NULL));
printf("\n\n\n");
printf("-------------Welcome to Rock-Paper-Scissors Game-------------\n");
printf("-----Instructions.-----\n");
printf("--> 1.Select 'r' for Rock.\n");
printf("--> 2.Select 'p' for Paper.\n");
printf("--> 3.Select 's' for Stone.\n");
printf("-->4. E for exit.\n");
while(1)
{
printf("Enter Your Choice.");
scanf(" %c", &a);
if(a == 'E'||a == 'e')
{
printf("You made an exit:\nThank you for Playing!!\n");
break;
}
if(a!='r'&&a!='p'&&a!='s')
{
printf("Please select a valid Input from:'r';'p';'s':");
continue;
}
int b = rand() % 3;
if (b == 0)
{
b = 'r';
}
else if (b == 1) b = 'p';
else b = 's';
printf("Computer chose: %c\n", b);
if (a == b) {
printf("Ohh! It's a draw!\n");
} else if ((a == 'r' && b == 'p') || (a == 'p' && b == 's') || (a == 's' && b == 'r'))
{
printf("Shoot! You Lost & Computer Wins!!\n");
g++;
} else
{
printf("Congratulations!! You Win!!\n");
h++;
}
printf("---------- Scoreboard -----------\n");
printf(" Computer | Player 2 \n");
printf("------------------|-------------------\n");
printf(" %d | %d \n",g,h);
printf("------------------|-------------------\n");
}
}