#include "stdio.h"
#include "time.h"
#include "stdlib.h"
int x1,x2,z,sum,i,a,k;
int game(int x1,int x2)
{ srand(time(NULL));
i=1;
x1=rand()%6+1;
x2=rand()%6+1;
a=x1+x2;
sum=a;
printf("%d %d+%d=%d\n",i,x1,x2,a);
return a;
}
main()
{ int game(int x1,int x2);
k=game(x1,x2);
if(a==2||a==3||a==12)
{printf("player lost\n");break;}
else
{ if(a==7||a==11)
{printf("player win\n");break;}
else
printf(" again?\n");
for(i=2;i>1;i++)
{ x1=rand()%6+1;
x2=rand()%6+1;
k=x1+x2;;
printf("%d %d+%d=%d\n",i,x1,x2,k); getch();
if(k==sum||k==7)
{ if(k==sum)
{printf("player win\n");
break;}
else
{printf("player lost\n");
break;}
}
else
printf(" again?\n");
}
}
getch();
}
为什么在红色部分不可以用,绿色部分可以用,红色后用就错?
请高手帮忙啊!!!谁可以教教啊!!!