c语言编程:猜数字游戏?

c语言编程:猜数字游戏?,第1张

#include <time.h>

#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

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11067257.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-13
下一篇 2023-05-13

发表评论

登录后才能评论

评论列表(0条)

保存