-
Notifications
You must be signed in to change notification settings - Fork 0
/
concentrationgame.c
77 lines (65 loc) · 1.56 KB
/
concentrationgame.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
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#define TURN_NUMBER 2
int randomNumber();
void putInArray(int put, int array[], int index);
int main()
{
int turn = 1;
int numberHolder[10];
bool win = true;
int currTime, elapsedTime = 0;
printf("Let's play concentration game with 10 numbers\n");
int index = 0;
while ( turn <= TURN_NUMBER && win)
{
int newNumber = randomNumber();
int j;
putInArray(newNumber, numberHolder, index);
index ++;
for(j = 0; j <= turn; j++)
{
printf("%d \n", numberHolder[j]);
}
currTime = time(NULL);
do
{
elapsedTime = time(NULL);
} while ((elapsedTime - currTime) < 3);
system("cls");
printf("What were the numbers? \n");
int d = 0;
for(d; d <= turn;d++)
{
int ans;
scanf("%d", &ans);
if(ans != numberHolder[d])
{
win = false;
goto loss;
}
}
system("cls");
if(turn == TURN_NUMBER && win)
{
printf("congratultions you won");
}
turn ++;
}
loss:
if(!win)
printf("shame you lost");
return 0;
}
int randomNumber()
{
int gen = 0;
srand(time(NULL));
gen = rand() % 100;
return gen;
}
void putInArray(int put, int array[], int index)
{
array[index] = put;
}