#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;
}
}
温馨提示:答案为网友推荐,仅供参考