在下面:
[此贴子已经被作者于2005-1-6 1:44:32编辑过]
我换个地方再帖一次吧
我改写了书上的一个猜数游戏,运行正常,但出现一个非常奇怪的问题:
加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编辑过]