equal
deleted
inserted
replaced
|
1 #include <stdio.h> |
|
2 #include <stdlib.h> |
|
3 |
|
4 #define getrandom(max) (1+(int)((float)(max)*rand()/RAND_MAX+1.0)) |
|
5 |
|
6 int main (void) |
|
7 { |
|
8 while (1) { |
|
9 int guess = -1, value = getrandom (100), count = 0; |
|
10 do { |
|
11 printf ("Enter a number: "); |
|
12 if (scanf ("%d", &guess) < 0) |
|
13 (void)getchar (); |
|
14 else |
|
15 count++; |
|
16 if (guess != value) |
|
17 printf ("X is %s than %d\n", (value > guess) ? "higher" : "lower", guess); |
|
18 } while (value != guess); |
|
19 printf ("SUCCESS: You got it after %d attempts\n", count); |
|
20 } |
|
21 return EXIT_SUCCESS; |
|
22 } |