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
| #define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #include <math.h> #include<stdlib.h> #include<time.h> #include<windows.h> void menu( ) { printf("\t\t\t\t********************\t\t\t\t\n"); printf("\t\t\t\t****** 1.play ******\t\t\t\t\n"); printf("\t\t\t\t****** 0.exit ******\t\t\t\t\n"); printf("\t\t\t\t********************\t\t\t\t\n"); } void game( ) { int guess = 0; int r = rand()%100+1; while (1) { printf("\t\t\t\t猜数字:"); scanf("%d",&guess); if (guess < r) { printf("\t\t\t\t猜小了\n"); } else if(guess>r) { printf("\t\t\t\t猜大了\n"); } else { printf("\t\t\t\tNice! 猜对了\n"); break; } } } int main(void) { int input = 0; srand((unsigned int)time(NULL)); do { menu(); printf("\t\t\t\t请选择(1-100):"); scanf("%d",&input); switch (input) { case 1: game(); break; case 0: printf("\t\t\t\t退出游戏\n"); break; default: printf("\t\t\t\t输入错误\n"); break; } } while (input);
return 0; }
|