forked from malmhaug/C_AbsBegin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC7E3DiceRollingGame.c
81 lines (46 loc) · 1.85 KB
/
C7E3DiceRollingGame.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
/* Challanges Ch7E3 - DiceRollingGame */
// By Jim-Kristian Malmhaug | Date: 8 October 2013
//Notes:
//References:
#include <stdio.h>
#include <unistd.h>
void TossDice(int *iPtr); //Function prototype the generates the random dice numbers.
int (*iPtr)[6];
main() {
int iSelect = 0;
int iDiceArray[6] = {0};
iPtr = &iDiceArray;
int i = 0;
do{
system("clear");
printf("\n\n*** Dice Rolling Game ***\n\nWhat would You do?\n\n1. Roll six dices.\n2. View the addresses\n3. Quit\n\n----> ");
scanf("%d", &iSelect);
switch(iSelect) {
case 1:
TossDice(iDiceArray);
printf("\n\nMessage: Your dices are -->");
for(i = 0 ; i < 6 ; i++) {
printf(" %d", iDiceArray[i]);
}
break;
case 2:
printf("\n\nFirst address of iPtr is %p and adress of iDiceArray[0] is %p\n", iPtr, &iDiceArray[0]);
sleep(3);
break;
case 3:
printf("\n\nThank You for playing!\n\n");
break;
}
} while(iSelect != 3);
} //End of main()-function
/*****************************************************
FUNCTION DEFINITION
TossDice()
*****************************************************/
void TossDice(int *iPtr) {
srand(time());
int j = 0;
for(j = 0 ; j < 6 ; j++) {
iPtr[j] = ((rand() % 6) + 1);
}
}