-
Notifications
You must be signed in to change notification settings - Fork 0
/
guess.c
37 lines (29 loc) · 767 Bytes
/
guess.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
//
// Created by user on 2023/9/16.
//
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void){
int high = 100;
int chance = 7;
printf("The computer will generate a random number between 1 and %d\n"
"You have %d chances",high,chance);
srand(time(NULL)); //use current time as seed for random generator
int secret = rand()%high + 1;
while(chance > 0) {
printf("Enter your guess.\n");
int guess;
scanf("%d", &guess);
if (guess == secret) {
printf("You Win!\n");
break;
} else if (guess > secret) {
printf(("guess > secret\n"));
} else {
printf("guess < secret\n");
}
chance--;
}
return 0;
}