7-24 猜数字游戏
1 #include <stdio.h> 2 3 int main(void) 4 { 5 int magic_number, n; 6 int guess_number; 7 int count = 0; 8 9 scanf("%d %d", &magic_number, &n); 10 11 do 12 { 13 scanf("%d", &guess_number); 14 if (guess_number < 0) 15 { 16 printf("Game Over\n"); 17 break; 18 } 19 20 count++; 21 if (guess_number > magic_number) 22 { 23 printf("Too big\n"); 24 } 25 else if (guess_number < magic_number) 26 { 27 printf("Too small\n"); 28 } 29 else 30 { 31 if (count == 1) 32 { 33 printf("Bingo!\n"); 34 } 35 else if (count <= 3) 36 { 37 printf("Lucky You!\n"); 38 } 39 else 40 { 41 printf("Good Guess!\n"); 42 } 43 break; 44 } 45 46 } while (count < n); 47 48 if (count == n && magic_number != guess_number) 49 { 50 printf("Game Over\n"); 51 } 52 53 return 0; 54 }