-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame_Of_Chance.cpp
More file actions
79 lines (71 loc) · 1.32 KB
/
Game_Of_Chance.cpp
File metadata and controls
79 lines (71 loc) · 1.32 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
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#define SEED 12345
void play(void);
int thro(void);
main()
{
char answer='Y';
printf("Wel Come To The Game Of CRAPS\n\n");
printf("To Throw The Dice Press ENTER\n\n");
srand(SEED);
while(toupper(answer) !='N')
{
play();
printf("\nDo You Want To Play Again ? (Y/N)");
scanf("%c",&answer);
printf("\n");
}
printf("Good Bye ,Have A Nice Day");
}
void play(void)
{
int score1,score2;
char dummy;
printf("\n\nPlease Throw The Dice......");
scanf("%c",&dummy);
printf("\n");
score1=thro();
printf("\n%2d",score1);
switch(score1)
{
case 7:
case 11:
printf("-Congratulations ! You Win On The First Throw\n");
break;
case 2:
case 3:
case 12:
printf("-Sorry You LOSE On The First Throw\n");
break;
case 4:
case 5:
case 6:
case 8:
case 9:
case 10:
do{
printf("-Throw The Dice Again....");
scanf("%c",&dummy);
score2=thro();
printf("\n%2d",score2);
} while(score2 !=score1&&score2 !=7);
if(score2==score1)
printf("--You Win By Matching Your First Score--\n");
else
printf("--You Lose By Faling To Match Your First Score\n\n");
break;
}
return;
}
int thro(void)
{
float x1,x2;
int n1,n2;
x1=rand()/32768.0;
x2=rand()/32768.0;
n1=1+(int)(6*x1);
n2=1+(int)(6*x2);
return(n1+n2);
}