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

Python018

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

}

#include<stdio.h>

#include<string.h>

void main(){

char str[100]

int num=2

do{

if(num<2||num>3){

printf("判断是数在2到3之间!\n\n")

break

}

printf("我猜这个数字是%d!\n",num)

scanf("%s",&str)

if(strcmp(str, "大了") == 0){

num--

continue

}else if(strcmp(str, "小了") == 0){

num++

continue

}else if(strcmp(str, "正确") == 0){

break

}else{

printf("输入错误!\n\n")

continue

}

}while(1==1)

}