本帖最后由 jackz007 于 2022-9-19 23:44 编辑 #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define count 5
int main(void)
{
int i , guess , secret ;
time_t t ;
srand((unsigned) time(& t)) ;
secret = rand() % 11 ; // 产生 0 ~ 10 的随机整数
for(i = 0 ; i < count ; i ++) {
printf("please input the num your gusse (0 ~ 10) : ") ;
scanf("%d", & guess) ;
if(guess == secret) {
printf("WOW YOU ARE SO SMART!!!\n") ;
break ;
} else {
if(guess > secret) printf("GUY ! You are bigger than that num !\n") ;
else printf("GUY ! You are so SMALL !!!hhh.\n") ;
if(i < count - 1)printf("And you only have %d option!\n\n" , count - i - 1) ;
}
}
printf("GAME OVER !\n") ;
}
编译、运行实况D:\[00.Exerciese.2022]\C>g++ -o x x.c
D:\[00.Exerciese.2022]\C>x
please input the num you gusse (0 ~ 10) : 7
GUY ! You are bigger than that num !
And you only have 4 option!
please input the num you gusse (0 ~ 10) : 4
GUY ! You are so SMALL !!!hhh.
And you only have 3 option!
please input the num you gusse (0 ~ 10) : 5
GUY ! You are so SMALL !!!hhh.
And you only have 2 option!
please input the num you gusse (0 ~ 10) : 6
WOW YOU ARE SO SMART!!!
GAME OVER !
D:\[00.Exerciese.2022]\C>
|