做一个猜数字 小软件

2025-06-20 14:59:43
推荐回答(1个)
回答1:

用什么做都挺容易的,关键是这个程序本身不难。
我看到一个小程序集锦里有个类似的程序,不过和你的要求不一样。正好前段时间我自己没事,已经调好了,贴下面了,你自己改哦。
#include "stdafx.h"
#include "headers.h"

#include
#include
#include

void guessNumber()
{
clock_t start,end;
time_t a,b;
double var;
int result,guess;
srand(time(NULL));
printf("I will offer an INTEGER number between 0 and 100,\n");
printf(" and you will guess which it is.\n");
printf("Do you want to play it ?('y' or 'n')\n");

while(getchar()=='y'||getchar()=='Y')
{
fflush(stdin);
result=rand()%100;
printf("\nPlease input the number you guess: \n");
start=clock();
a=time(NULL);
scanf("%d",&guess);
fflush(stdin);
while(guess!=result)
{
if(guess>result)
{
printf("Please input a little smaller: \n");
scanf("%d",&guess);
fflush(stdin);
}
else
{
printf("Please input a little bigger: \n");
scanf("%d",&guess);
fflush(stdin);
}
}
end=clock();
b=time(NULL);
printf("\1\1 Congradulations \1\1\n");
printf("The number you guess is %d\n\n",result);

printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2/100);
if(var<15)
printf("\1\1 You are very clever! \1\1\n");
else if(var<25)
printf("\1\1 you are normal! \1\1\n");
else
printf("\1\1 you are stupid! \1\1\n");

printf("\nDo you want to try it again ?(y or n)\n");
}
fflush(stdin);
}