forked from randerson112358/C-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
guessing_game2.c
53 lines (36 loc) · 1.3 KB
/
guessing_game2.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
# include <stdio.h>
# include <time.h>
# include <stdlib.h>
//# include <math.h>
int main (void)
{
int seed = time(NULL);
srand(seed);
int randomNumber = 1 + (rand() % 100);
int numGuesses = 0;
int guess;
printf("I'm guessing a random number 1 to 100 can u guess what it is?\nYou have 10 guesses:\n");
do
{
scanf("%d", &guess);
numGuesses ++;
if(guess == randomNumber)
{
printf("Great Job, you guessed my number correctly, in only %d turns\n",numGuesses);
}
else if( guess < randomNumber )
{
printf("The number Im thinking of is higher than that.\n");
}
else if( guess > randomNumber )
{
printf("The number Im thinking of is lower than that.\n");
}
}while(numGuesses < 10 || guess == randomNumber);
if( numGuesses == 10 )
{
printf("Sorry you've exceeded the number of tries to guess the random number %d\n\n", randomNumber);
printf("You Lose !\n");
}
//system("pause");
}