| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 989 人关注过本帖
标题:只差一点点了,请教。。。
只看楼主 加入收藏
糖玩儿
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-1
收藏
 问题点数:0 回复次数:14 
只差一点点了,请教。。。

谢谢各位了!

现在可以运行了,可是我们的要求是当用户10次仍然不能猜出正确的原始数字和顺序时,系统提示玩家失败,并给玩家显示原始数字和顺序。

我觉得只要在外面加一条FOR就行了。可是猜错十次以后还是老样子。难道我做的循环不对吗?
怎样才能在最后把开始随机生成的4个数字显示出来呢??

我刚才照windflush说的做了,把for放进while去。
可是应该放在哪儿呢?
怎样才能不让黄色的部分一直循环呢?
哥哥们,帮帮忙吧。我也知道编的乱,可是这是作业,就要提交了,急!!死!!!


#include "stdafx.h"


#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define SIZE 4
main()
{ int enter=1,stop,a[SIZE],b[SIZE],guessnum,i,j,counter,countera,counterb,counter0,extra;
int t;
for(t=0;t<10;t++)
{ //int enter=1,stop,a[SIZE],b[SIZE],guessnum,i,j,counter,countera,counterb,counter0,extra;
char ch;
srand(time(NULL));

while(enter==1)
{ stop=2;

while(stop==2)
{ extra=1;
for(i=0;i<=SIZE-1;i++)
a[i]=rand()%10;
for(i=0;i<=SIZE-1;i++)
{ for(j=i+1;j<=SIZE-1;j++)
{ if(a[i]==a[j]) extra=2; }
}
if(a[0]!=0&&extra==1) {stop=1;printf("%d%d%d%d",a[0],a[1],a[2],a[3]);}
}

counter=1;
while(counter<=6)
{ printf("Please guess the number:\n");
scanf("%d",&guessnum);
for(i=0;i<=SIZE-1;i++)
b[i]=guessnum/(int)pow(10,SIZE-1-i)%10;
countera=0;
for(i=0;i<=SIZE-1;i++)
{ if(a[i]==b[i]) countera++;}
counter0=0;
for(i=0;i<=SIZE-1;i++)
{ for(j=0;j<=SIZE-1;j++)
{ if(a[i]==b[j]) counter0++;}
}
counterb=(counter0-countera);
if(countera==4)
{ printf("Wonderful!You guessed the number.Then,please input your choice,'1' represents going on,'2' represents breaking\n");
counter=7;
scanf("%d",&enter);
}
else{ printf("%dA%dB\n",countera,counterb);
counter++;
}
}
}

while((ch=getchar())!='s'&&ch!='S');
};
printf("你失败了,答案是:%d%d%d%d\n",a[0],a[1],a[2],a[3]);

return 0;
}




[此贴子已经被作者于2007-7-1 20:52:41编辑过]

搜索更多相关主题的帖子: color 哥哥 黄色 用户 
2007-07-01 01:13
a307871404
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2007-6-19
收藏
得分:0 

楼主把你那个 "stdafx.h"文件发上来让大家参考下


我让我喜欢的人不开心     真没用
2007-07-01 09:23
cihren
Rank: 1
等 级:新手上路
帖 子:76
专家分:0
注 册:2007-6-27
收藏
得分:0 

我给你理了一下,太糟糕了,你这样写有错能找着才怪了
这错误显而易见.....

//#include "stdafx.h" 这句没实际意义,我给注释了

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define SIZE 4
main()
{ int enter=1,stop,a[SIZE],b[SIZE],guessnum,i,j,counter,countera,counterb,counter0,extra;
int t;
for(t=0;t<11;t++)
{ //int enter=1,stop,a[SIZE],b[SIZE],guessnum,i,j,counter,countera,counterb,counter0,extra;
char ch;
srand(time(NULL));

while(enter==1)
{ stop=2;

while(stop==2)
{ extra=1;
for(i=0;i<=SIZE-1;i++)
a[i]=rand()%10;
for(i=0;i<=SIZE-1;i++)
{ for(j=i+1;j<=SIZE-1;j++)
{ if(a[i]==a[j]) extra=2; }
}
if(a[0]!=0&&extra==1) {stop=1;printf("%d%d%d%d",a[0],a[1],a[2],a[3]);}
}

counter=1;
while(counter<=6)
{ printf("Please guess the number:\n");
scanf("%d",&guessnum);
for(i=0;i<=SIZE-1;i++)
b[i]=guessnum/(int)pow(10,SIZE-1-i)%10;
countera=0;
for(i=0;i<=SIZE-1;i++)
{ if(a[i]==b[i]) countera++;}
counter0=0;
for(i=0;i<=SIZE-1;i++)
{ for(j=0;j<=SIZE-1;j++)
{ if(a[i]==b[j]) counter0++;}
}
counterb=(counter0-countera);
if(countera==4)
{ printf("Wonderful!You guessed the number.Then,please input your choice,'1' represents going on,'2' represents breaking\n");
counter=7;
scanf("%d",&enter);
}
else{ printf("%dA%dB\n",countera,counterb);
counter++;
}
}
}

while((ch=getchar())!='s'&&ch!='S');
};
printf("你失败了,答案是:%d%d%d%d\n",a[0],a[1],a[2],a[3]);

return 0;
}


革命尚未成功,同志仍需努力!
2007-07-01 09:44
糖玩儿
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-1
收藏
得分:0 
谢谢各位了!

现在可以运行了,可是我们的要求是当用户10次仍然不能猜出正确的原始数字和顺序时,系统提示玩家失败,并给玩家显示原始数字和顺序

我觉得只要在外面加一条FOR就行了。可是猜错十次以后还是老样子。难道我做的循环不对吗?
怎样才能在最后把开始随机生成的4个数字显示出来呢??

急!!死!!!

人血馒头
2007-07-01 12:09
windflush
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:886
专家分:0
注 册:2007-7-1
收藏
得分:0 

for(t=0;t<11;t++)


这句话来看的话,应该是猜11次吧???


2007-07-01 16:04
mp3aaa
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:2013
专家分:8
注 册:2006-2-15
收藏
得分:0 
说实话 程序写的有写乱 你吧程序要实现的功能说以下

羊肉串 葡萄干 哈密瓜!!
2007-07-01 16:05
mp3aaa
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:2013
专家分:8
注 册:2006-2-15
收藏
得分:0 

我发现了 程序一直都在黄色的部分 无限循环
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define SIZE 4
main()
{ int enter=1,stop,a[SIZE],b[SIZE],guessnum,i,j,counter,countera,counterb,counter0,extra,x=0;
int t;
for(t=0;t<10;t++,x++)
{ //int enter=1,stop,a[SIZE],b[SIZE],guessnum,i,j,counter,countera,counterb,counter0,extra;
char ch;
srand(time(NULL));

while(enter==1)
{ stop=2;

while(stop==2)
{ extra=1;
for(i=0;i<=SIZE-1;i++)
a[i]=rand()%10;
for(i=0;i<=SIZE-1;i++)
{ for(j=i+1;j<=SIZE-1;j++)
{ if(a[i]==a[j]) extra=2; }
}
if(a[0]!=0&&extra==1) {stop=1;printf("%d%d%d%d",a[0],a[1],a[2],a[3]);}
}

counter=1;
while(counter<=6)
{ printf("Please guess the number:\n");
scanf("%d",&guessnum),printf("----%d\n",x);
for(i=0;i<=SIZE-1;i++)
b[i]=guessnum/(int)pow(10,SIZE-1-i)%10;
countera=0;
for(i=0;i<=SIZE-1;i++)
{ if(a[i]==b[i]) countera++;}
counter0=0;
for(i=0;i<=SIZE-1;i++)
{ for(j=0;j<=SIZE-1;j++)
{ if(a[i]==b[j]) counter0++;}
}
counterb=(counter0-countera);
if(countera==4)
{ printf("Wonderful!You guessed the number.Then,please input your choice,'1' represents going on,'2' represents breaking\n");
counter=7;
scanf("%d",&enter);
}
else{ printf("%dA%dB\n",countera,counterb);
counter++;
}
}

}

// while((ch=getchar())!='s'&&ch!='S');
}
printf("你失败了,答案是:%d%d%d%d\n",a[0],a[1],a[2],a[3]);

return 0;
}


羊肉串 葡萄干 哈密瓜!!
2007-07-01 16:44
windflush
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:886
专家分:0
注 册:2007-7-1
收藏
得分:0 

if(countera==4)
{ printf("Wonderful!You guessed the number.Then,please input your choice,'1' represents going on,'2' represents breaking\n");
counter=7;
scanf("%d",&enter);
}


你这个对enter的判断是,答对时给选择,退出的话才改变enter的值,你的for循环应该放到while的循环体里头。


2007-07-01 16:56
糖玩儿
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-1
收藏
得分:0 
好,我试试

人血馒头
2007-07-01 20:14
糖玩儿
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-1
收藏
得分:0 


我刚才照windflush说的做了,把for放进while去。
可是应该放在哪儿呢?
怎样才能不让黄色的部分一直循环呢?
哥哥们,帮帮忙吧。我也知道编的乱,可是这是作业,就要提交了,我急啊。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define SIZE 4
main()
{ int enter=1,stop,a[SIZE],b[SIZE],guessnum,i,j,counter,countera,counterb,counter0,extra,x=0;
int t;
for(t=0;t<10;t++,x++)
{ //int enter=1,stop,a[SIZE],b[SIZE],guessnum,i,j,counter,countera,counterb,counter0,extra;
char ch;
srand(time(NULL));

while(enter==1)
{ stop=2;

while(stop==2)
{ extra=1;
for(i=0;i<=SIZE-1;i++)
a[i]=rand()%10;
for(i=0;i<=SIZE-1;i++)
{ for(j=i+1;j<=SIZE-1;j++)
{ if(a[i]==a[j]) extra=2; }
}
if(a[0]!=0&&extra==1) {stop=1;printf("%d%d%d%d",a[0],a[1],a[2],a[3]);}
}

counter=1;
while(counter<=6)
{ printf("Please guess the number:\n");
scanf("%d",&guessnum),printf("----%d\n",x);
for(i=0;i<=SIZE-1;i++)
b[i]=guessnum/(int)pow(10,SIZE-1-i)%10;
countera=0;
for(i=0;i<=SIZE-1;i++)
{ if(a[i]==b[i]) countera++;}
counter0=0;
for(i=0;i<=SIZE-1;i++)
{ for(j=0;j<=SIZE-1;j++)
{ if(a[i]==b[j]) counter0++;}
}
counterb=(counter0-countera);
if(countera==4)
{ printf("Wonderful!You guessed the number.Then,please input your choice,'1' represents going on,'2' represents breaking\n");
counter=7;
scanf("%d",&enter);
}
else{ printf("%dA%dB\n",countera,counterb);
counter++;
}
}

}

// while((ch=getchar())!='s'&&ch!='S');
}
printf("你失败了,答案是:%d%d%d%d\n",a[0],a[1],a[2],a[3]);

return 0;
}


人血馒头
2007-07-01 20:43
快速回复:只差一点点了,请教。。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022564 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved