给100分,能准确运行的时候就行,诚心感谢
不要其他的代码。就是找出这段代码的问题。运行咋有问题,我找累了
程序代码:#include<stdio.h>
#include <string.h>
#include <time.h>
#include <conio.h>
#include <stdlib.h>
int numbe2[4]={0};
int numb2[4];
void init()//产生随机数种子
{
srand(time(0));
}
int *creat()//产生4个各不相同的随机数函数 ,把四个数保存在数组中,返回值是该数组的首地址
{
int flag[10]={0};
int *p;
p=numbe2;
int tem=0,i=5,j=4;
while(i)
{
tem=rand()%10;
if(flag[tem]==0)
{
numbe2[j]=tem;
flag[tem]=1;
j--,i--;
};
}
return p;
}
int check(int *numbb,int *numbb2)//比较随机数数组和保存输入4个数的函数
{ int x=0,y=0,m,n;
for( n=0;n<4;n++)
for( m=0;m<4;m++)
{ if(numbb[n]==numbb2[m])
{
if(n==m)
{
x++;
}
else y++;
}
}
if(x==4)
{
printf("恭喜你答对了!猜中的数字是%d%d%d%d",numbb[0],numbb[1],numbb[2],numbb[3]);
return x;
}
else{
printf("%dA%dB",x,y);
return 0;
}
}
void start()//游戏开始
{ int *numb;
char numb3='\0';//结束标志保存在字符变量numb3中
int i=0;
numb=creat();
while(i<7)
{
fflush(stdin);//清空缓存
printf("请输入4个数,这是你第%d次猜\n",i+1);
while(1)
{
if((scanf("%d%d%d%d",&numb2[0],&numb2[1],&numb2[2],&numb2[3])==4)&&(numb3==getchar()))// scanf格式读取四个数,正确输入第5个应该是'\0'
{
break;
}
else {
fflush(stdin);
printf("输入错误,请重新输入\n");
}
printf("按Q/q退出\n");
if('Q'==getch()||'q'==getch())
exit(0);
}
if(check(numb,numb2))//调用check函数,返回值是4的话,退出while(i<7)循环
{
break;
}
else//返回值是0的话就i++,然后继续内循环while
{
i++;
continue;
}
}
}
int main(void)
{
init();
start();
}[ 本帖最后由 a271885843 于 2012-7-2 22:01 编辑 ]










