最近在做一个龟兔赛跑程序,写完后想在画条跑道,改了几次都无法执行,求指点(下面是没加跑到之前的设计)。。。

wk877836440 2011-03-18 11:50:46
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>

void guitu( );

main( )
{
srand(time(NULL));
guitu();
return 0;
}

void guitu()
{
int i,j,a=0,b=0,number;
char lucheng[71];
while(1)
{
for(j=0;j<70;j++)
lucheng[j]=' ';
lucheng[71]=' ';
number=1+rand()%10;
printf("n");
if(1<=number && number<=5)
{
a=a+3;
if(a>70) a=0;
lucheng[a]='G';
}
if(6<=number && number<=7)
{
a=a-6;
if(a<0) a=0;
lucheng[a]='G';
}
if(8<=number && number<=10)
{
a=a+1;
if(a>70) a=0;
lucheng[a]='G';
}
if(1<=number && number<=2)
{
b=b+0;
lucheng[b]='T';
}
if(3<=number && number<=4)
{
b=b+9;
if(b>70) b=0;
lucheng[b]='T';
}
if(number==5)
{
b=b-12;
if(b<0) b=0;
lucheng[b]='T';
}
if(6<=number && number<=8)
{
b=b+1;
if(b>70) b=0;
lucheng[b]='T';
}
if(9<=number && number<=10)
{
b=b-2;
if(b<0) b=0;
lucheng[b]='T';
}
if(a==b)
lucheng[a]='P';
printf("%s",lucheng);
printf("nn");
if(a==70)
{
printf("gui win!!!nn");
break;
}
if(b==70)
{
printf("tu win!!!nn");
break;
}
sleep(1);
}
}
...全文
121 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2011-03-18
  • 打赏
  • 举报
回复
改用gotoxy和cprintf?
moorsf 2011-03-18
  • 打赏
  • 举报
回复
其它自己调试吧

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>

void guitu( );

int main( )
{
srand(time(NULL));
guitu();
return 0;
}

void guitu()
{
int j,a=0,b=0,number;
char lucheng[71];
while(1)
{
for(j=0; j<70; j++)
lucheng[j]=' ';
lucheng[70]='\0';
number=1+rand()%10;
//printf("\n");
if(1<=number && number<=5)
{
a=a+3;
if(a>70) a=0;
lucheng[a]='G';
}
if(6<=number && number<=7)
{
a=a-6;
if(a<0) a=0;
lucheng[a]='G';
}
if(8<=number && number<=10)
{
a=a+1;
if(a>70) a=0;
lucheng[a]='G';
}
if(1<=number && number<=2)
{
b=b+0;
lucheng[b]='T';
}
if(3<=number && number<=4)
{
b=b+9;
if(b>70) b=0;
lucheng[b]='T';
}
if(number==5)
{
b=b-12;
if(b<0) b=0;
lucheng[b]='T';
}
if(6<=number && number<=8)
{
b=b+1;
if(b>70) b=0;
lucheng[b]='T';
}
if(9<=number && number<=10)
{
b=b-2;
if(b<0) b=0;
lucheng[b]='T';
}
if(a==b)
lucheng[a]='P';
printf("%s",lucheng);
printf("\n");
if(a==70)
{
printf("gui win!!!\n");
break;
}
if(b==70)
{
printf("tu win!!!\n");
break;
}
sleep(1);
}
}
wk877836440 2011-03-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 moorsf 的回复:]
其它自己调试吧


C/C++ code
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>

void guitu( );

int main( )
{
srand(time(NULL));
guitu();
return 0;
}

void gu……
[/Quote]那怎么加一个跑道呢?我使用了<graphics.h>头文件。在主函数中guitu();函数之前加了一段


int drive,mode=0;
drive=DETECT;
initgraph(&drive,&mode,"");
setbkcolor(BLACK);
setcolor(YELLOW);
moveto(0,20);
linerel(70,20);
getch();
closegraph();

不好意思啊,上面忘了把题目写出来。
1:乌龟规则:50%机会进3,,2%退6,30%进1
2:腿子规则:20%不动,20%前进9格,10%后退12格,30%前进1,20%后退2.
3:最先走到70得胜,走过了从头再来

我关键是跑到加不上去,没有错误,但执行不了,

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧