bigbangtop带过的手表:好心的大侠啊,进来帮帮我啊!

来源:百度文库 编辑:中科新闻网 时间:2024/04/28 05:31:09
真是有点亏啊,我才学C语言一个学期,老师却要我编程序,而且是个对我来说有点夸张的程序.我要编的程序是一个猜字游戏.
功能要求:
计算机产生随机数,猜中即胜,猜不中,提示大了还是小了,继续猜,直到猜到,给出所用时间和评语.
哎!都怪我笨.没好好学.编了几天都没搞出来.就要交作业了.不然就挂科.
好心的大侠们啊,救救我啊.我将感激不竟啊.

#include "time.h"
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
main()
{
char c;
clock_t start,end;
time_t a,b;
double var;
int i,guess;
srand(time(NULL));
printf("do you want to play it.('y' or 'n') \n");
loop:
while((c=getchar())=='y')
{
i=rand()%100;
printf("\nplease input number you guess:\n");
start=clock();
a=time(NULL);
scanf("%d",&guess);
while(guess!=i)
{
if(guess>i)
{
printf("please input a little smaller.\n");
scanf("%d",&guess);
}
else
{
printf("please input a little bigger.\n");
scanf("%d",&guess);
}
}
end=clock();
b=time(NULL);
printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2);
printf("\1: it took you %6.3f seconds\n\n",difftime(b,a));
if(var<15)
printf("\1\1 You are very clever! \1\1\n\n");
else if(var<25)
printf("\1\1 you are normal! \1\1\n\n");
else
printf("\1\1 you are stupid! \1\1\n\n");
printf("\1\1 Congradulations \1\1\n\n");
printf("The number you guess is %d",i);
}
printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");
if((c=getch())=='y')
goto loop;
}

#include <stdio.h>
#include <time.h>
void main()
{
int i;
int j;
srand( (unsigned)time( NULL ) ); //产生随机数种子;
i = rand(); //产生随机数;
while(TRUE)
{
printf("Enter a number..");
scanf("%d",&j);
if(j>i) printf("The number is bigger than rand,please try again"); //如果输入数大于随机数,继续
elseif(j<i) printf("The number is smaller than rand,please try again");//如果输入数小于随机数,继续
else //相等,退出循环
{
printf("OK!");
break;
}
}
}