#include <stdio.h>
#include <stdlib.h>
#define UI unsigned short int
void game()
{
UI answer
UI input
UI lower=1
UI upper=100
UI count=0
srand(time(NULL))
do{answer=rand()%101}
while(answer==0)
puts("Welcome to the number guessing game!")
do
{
puts("Please enter an integer from 1 to 100 (again):")
scanf("%lu",&input)
getchar()
count=count+1
if(input==answer){puts("You succeeded!")printf("The number of time(s) you entered is %lu.\n",count)}
else
{
puts("You failed!")
if(input<answer){if(input>lower){lower=input}puts("The answer is greater than your input.")}
else{if(input<upper){upper=input}puts("The answer is less than your input.")}
printf("The answer is from %lu to %lu.\n",lower,upper)
}
}
while(input!=answer)
}
#undef UI
int main()
{
game()
system("Pause")
return 0
}
//小游戏:猜数字 随机一个1-100之间的数,根据数据输入进行提示#include <stdlib.h>
#include <time.h>
int main(void){
int value=0
int num=0
srand((unsigned int) time(NULL))
num=rand()%100+1//1-100
while(1){
scanf("%d",&value)
if(num>value){
printf("您猜小了\n")
}
else if(num<value){
printf("您猜大了\n")
}
else if(num=value){
printf("恭喜您猜对了\n")
break
}
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)