在下面:
[此贴子已经被作者于2005-1-6 1:44:32编辑过]
----------------解决方案--------------------------------------------------------
找一下,这个问题在这里不知讨论过多少次了
----------------解决方案--------------------------------------------------------
字体不要用斜体,我们看得很辛苦,特别小弟发烧,看得倒转了。
----------------解决方案--------------------------------------------------------
我原来是正体呀,不知怎的,就变成这样了.
shdurhfjfk
----------------解决方案--------------------------------------------------------
我换个地方再帖一次吧
我改写了书上的一个猜数游戏,运行正常,但出现一个非常奇怪的问题:
加RANDOMIZE():TURBO C FOR WINDOWS,WIN-TC通不过,随机生数器RAND()每次都产生一样的数,重新运行也一样,再先运行其他程序再运行它一样,
重复加上那个随机生数器RAND()语句(),只改变一次,再运行还是出一样的数 tc for windows, wintc都一样
我极度震惊! 不解! 望高手解我心头之惑! 这个游戏我弄了一天了!
多谢,急等.. #include <math.h> #include <stdlib.h> #include <stdio.h> #include <process.h> #include <conio.h> main() { int answer[4]={0,0,0,0},guess,times=0,a=0,b,i,j,score;
clrscr(); for(i=0;i<4;i++) { randomize(); /*加上randomize();TURBO C FOR WINDOWS,WIN-TC通不过*/ answer[i]=rand()%10; /*就在这里*/ answer[i]=rand()%10; for(j=0;j<i;j++) {while(answer[i]==answer[j]) {answer[i]=rand()%10; j=-1; } } } window(60,15,70,20); textcolor(YELLOW); textbackground(GREEN); /*textattr(128+12+6);*/
cprintf("please input a number to guess\n\r"); while(a!=4) { a=0;b=0;times++;
do {window(10,0,40,21); cprintf("\r%d ",times); if(cscanf("%d",&guess)==0) exit(0); }while(guess<0||guess>9999);
for(i=3;i>-1;i--) { for(j=0;j<4;j++) {if((int) (guess/pow10(i))==answer[j]) {if(i+j==3) a=a+1; else b=b+1; } } guess=guess-(int) (guess/pow10(i))*pow10(i); } window(20,0,40,31); cprintf("\n\r %dA%dB\n",a,b); }
if(times==1) {score=100; goto score;} if(times>1&×<=2) {score=90; goto score;} if(times>2&×<=3) {score=80; goto score;} if(times>3&×<=4) {score=70; goto score;} if(times>4&×<=5) {score=60; goto score;} if(times>5&×<=6) {score=50; goto score;} if(times>6&×<=7) {score=40; goto score;} if(times>7&×<=8) {score=30; goto score;} if(times>8&×<=9) {score=20; goto score;} if(times>9&×<=10) {score=10; goto score;} if(times>10&×<=11) goto score2; if(times>11) goto score3;
score: printf("congradulations! you guessed right! your score is %d, because you used %d times, byebye!\n",score,times); goto end; score2: printf("you guessed right, but you're a fool!, because you used %d times\n",times); goto end; score3: printf("you guessed right, but you're too foolish! because you used %d times!\n",times); end:; getch(); }
[此贴子已经被作者于2005-1-6 12:24:58编辑过]
----------------解决方案--------------------------------------------------------
是的这个问题问的次数太多了,就是用randomize()函数初始化随机数发生器以后再用rand()函数就可以了!
----------------解决方案--------------------------------------------------------
我加过RANDOMIZE(); TURBO C FOR WINDOWS 通不过.
所以才问嘛
----------------解决方案--------------------------------------------------------
@grub2linux: #include <time.h> 改用这个srand(time(0)); @knocker斑竹 关于你的签名... “我偷了比尔的窗口,我却看到窗外是一个阳光的自由的开放的unix。” unix也不是自由开放的.所以才有GNU(GNU Not Unix)的开放协议:)
----------------解决方案--------------------------------------------------------
谢谢kaikai提醒(晕啊,C++的有个kai,现在又来了个kaikai??哈哈),我胡乱写写的^_^,要不改成linux?
----------------解决方案--------------------------------------------------------
我c++不行的...呵呵。
----------------解决方案--------------------------------------------------------