-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_num_gen.c
184 lines (107 loc) · 1.42 KB
/
random_num_gen.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
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
/*
* Name: Abhiram Chavakula
* Pawprint:avc9wb
* Lab code: random number generator
* Student #14207755
*/
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int random_number();
void display_option();
int check_guess(int);
int throw_dice();
int lucky_seven(int, int);
int sum;
int main ()
{
int guess, a;
srand(time(NULL));
display_option();
scanf("%d", &guess);
while (check_guess(guess)==0)
{
printf("Invalid choice\n");
display_option();
scanf("%d",&guess);
}
sum=throw_dice();
a=lucky_seven(guess, sum);
if (a==1)
{
printf("You win! Your guess is correct, the sum of the dice is %d\n", sum);
}
else
{
printf("You lose! Your guess is incorrect, the sum of the dice is %d\n", sum);
}
//int x;
//x=random_number();
//printf("\n Random number is %d \n", x);
return 0;
}
/*int random_number()
{
int num;
num= rand()%10;
return num;
}*/
void display_option()
{
printf("Enter your guess (1) Lucky 7 (2) Above 7 (3) Below 7:\n Please select an option:");
}
int check_guess(int guess)
{
if (guess<1 || guess>3)
{
return 0;
}
else
return 1;
}
int throw_dice()
{
int x, y;
x=rand()%6+1;
y=rand()%6+1;
sum=x+y;
return sum;
}
int lucky_seven(guess, sum)
{
switch (guess)
{
case 1:
if (sum==7)
{
return 1;
}
else
{
return 0;
}
break;
case 2:
if (sum>7)
{
return 1;
}
else
{
return 0;
}
break;
case 3:
if (sum<7)
{
return 1;
}
else
{
return 0;
}
break;
return 1;
}
return 0;
}