一道简单C语言程序设计题

猜数字游戏
程序功能要求:利用随机函数srand((unsigned)time(NULL));和rand()
生成1---N之间的一个整数,输入数字猜该数,每次提示输入的数字与生
成的数字之间的大小关系,并统计猜数的次数;猜中后显示该数、猜数的
次数及等级(三次以内为优秀,七次以内为良好,否则为不及格)。程序要
求提示清楚,容错性能要好。

麻烦如果有时间附上个 实验报告 简短的提示下怎么写就行 谢谢

#include <stdio.h>
#include <time.h>
#define N 20
int GetTimes(int num)
{
int times=0,t;
while(1)
{

printf("Please input an integer:\n");
scanf("%d",&t);
if(t<0)
printf("Please input a plus integer!\n");
else
{
if(t==num)
{
times++;

break;
}
else if(t>num)
{
times++;

printf("The num %d is bigger than The Target :\n",t);
continue;
}
else if(t<num)
{
times++;
printf("The num %d is smaller than The Target:\n",t);

continue;
}
}
}
return times;

}
void main()
{
int times=0,num;

srand((unsigned)time(NULL));
num=rand()%N;
times=GetTimes(num);

switch(times)
{
case 1:{ system("cls"); printf("The Target is %-2d and you spend %d times!\n",num,times);printf("The level of your performance is :");printf("Very Well!\n");
}break;
case 2: { system("cls");printf("The Target is %-2d and you spend %d times!\n",num,times);printf("The level of your performance is :");printf("Very Well!\n");
}break;
case 3:{ system("cls"); printf("The Target is %-2d and you spend %d times!\n!",num,times);printf("The level of your performance is :");printf("Very Well!\n");
}break;
case 4: {system("cls");printf("The Target is %-2d and you spend %d times!\n!",num,times);printf("The level of your performance is :");
printf("GOOD!");}break;
case 5: {system("cls");printf("The Target is %-2d and you spend %d times!\n",num,times);printf("The level of your performance is :");
printf("GOOD!");}break;
case 6:{system("cls");printf("The Target is %-2d and you spend %d times!\n",num,times);printf("The level of your performance is :");
printf("GOOD!");}break;
case 7:{system("cls");printf("The Target is %-2d and you spend %d times!\n",num,times);printf("The level of your performance is :");
printf("GOOD!");}break;
default:{system("cls");printf("The Target is %-2d and you spend %d times!\n",num,times); printf("Actually,you failed!\n");
}break;
}

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-04-14
这个需要一些时间去写.
第2个回答  2009-04-14
给你发消息了
相似回答