-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rock_Ppr_Scis_Int1.C
89 lines (87 loc) · 2.28 KB
/
Rock_Ppr_Scis_Int1.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
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
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
//Creating rock-paper-scissors program...where your default opponent is your computer!
//The computer's moves will be absolutely unpredictable ;) & you can chose your own moves.
//After one set, the player(i.e. me ;)) could decide whether to play ahead or not.
//And yes...after each set the player comes to know who has won or if it's a tie!
//The rules are pretty simple....
//•Rock defeats scissors•
//•Scissors defeat paper•
//•Paper defeats rock•
//No cheats ;) It would be a 100% fair play :)
//In this code I am assuming computer's move as 'CYmove' & player's move as 'MYmove' :)
int main()
{
srand(time(NULL));
int CYmove,MYmove;
char Once_more;
int Keep_playing=1;
while(Keep_playing)
{
CYmove=rand()%3;
printf("Press '0' for Rock\nPress '1' for Paper\nPress '2' for Scissors\n");
printf("What do you chose : Rock, Paper or Scissors?\n");
scanf("\n%d",&MYmove);
//Now let's declare who has won
if(MYmove>2 || MYmove<0)
{
printf("Invalid choice ");
break;
}
else if(CYmove==MYmove)
{
printf("It is a Tie -_-\n");
}
else if (CYmove==0)
{
printf("The computer chose Rock!\n");
if(MYmove==1)
{
printf("You win :)\n");
}
if(MYmove==2)
{
printf("Computer wins :( Better luck next time!\n");
}
}
else if (CYmove==1)
{
printf("The computer chose Paper!\n");
if(MYmove==2)
{
printf("You win :)\n");
}
if(MYmove==0)
{
printf("Computer wins :( Better luck next time!\n");
}
}
else if (CYmove==2)
{
printf("The computer chose Scissors!\n");
if(MYmove==0)
{
printf("You win :)\n");
}
if(MYmove==1)
{
printf("Computer wins :( Better luck next time!\n");
}
}
printf("Do you wanna play again? Y/N\n");
scanf("\n%c",&Once_more);
if(Once_more=='Y' || Once_more== 'y')
{
Keep_playing=1;
printf("Yes! I knew it :) Let\'s go then...\n");
}
else
{
printf("Bye then...See you later •_•");
Keep_playing=0;
}
}
return 0;
}
//I'm sure you would have fun playing!