|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <dos.h>
void guess(int n)
{
int acount, bcount, i, j, k = 0, flag, a[10], b[10];
do
{
flag = 0;
srand((unsigned)time(NULL));
for(i = 0; i < n; i++)
a[i] = rand()%10;
for(i = 0; i < n - 1; i++)
{
for(j = i + 1; j < n; j++)
if(a[i] == a[j])
{
flag = 1;
break;
}
}
}while(flag == 1);
do
{
k++;
acount = 0;
bcount = 0;
printf("guess:");
for(i = 0; i < n; i++)
scanf("%d", &b[i]);
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
{
if(a[i] == b[i])
{
acount++;
break;
}
if(a[i] == b[j] && i != j)
{
bcount++;
break;
}
}
printf("clue on: %d A %d B\n\n", acount, bcount);
if(acount == n)
{
if(k == 1)
printf("you are the topmost rung of Fortune's ladder!! \n\n");
else if(k <= 5)
printf("you are genius!! \n\n");
else if(k <= 10)
printf("you are cleaver!! \n\n");
else
printf("you need try hard!! \n\n");
break;
}
}while(1);
}
void main()
{
int i, n;
while(1)
{
clrscr();
gotoxy(15, 6);
printf("1. start game?(y / n)");
gotoxy(15, 8);
printf("2. Rule");
gotoxy(15, 10);
printf("3. exit\n");
gotoxy(25, 15);
printf("please choose:");
scanf("%d", &i);
switch(i)
{
case 1:
clrscr();
printf("please input n:\n");
scanf("%d", &n);
guess(n);
sleep(5);
break;
case 2:
clrscr();
printf("\t\tThe Rules Of The Games\n");
printf("step1: input the number of digits\n");
printf("step2: input the number, separated by a space between two numbers\n");
printf("step3: A represent location and data are correct\n");
printf("\tB represent location is correct but data is wrong!\n");
sleep(10);
break;
case 3:
exit(0);
default:
break;
}
}
}
--------------------Configuration: 猜数字 - Win32 Debug--------------------
Compiling...
猜数字.c
D:\C语言\MSDev98\MyProjects\猜数字\猜数字.c(69) : warning C4013: 'clrscr' undefined; assuming extern returning int
D:\C语言\MSDev98\MyProjects\猜数字\猜数字.c(70) : warning C4013: 'gotoxy' undefined; assuming extern returning int
D:\C语言\MSDev98\MyProjects\猜数字\猜数字.c(86) : warning C4013: 'sleep' undefined; assuming extern returning int
猜数字.obj - 0 error(s), 0 warning(s)这是什么问题啊
|
|