『壹』 C語言的編程問題,不知道如何編碼,希望寫一遍代碼。謝謝
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
voidmain()
{inthp_a=100,hp_b=100,i=0;
intflag=0;
intattact;
srand((unsigned)time(NULL));
while(hp_a>0&&hp_b>0)
{
i++;
/*printf(" Round:%d ",i);*/
if(flag==0)
{
attact=rand()%(12-8+1)+8;
hp_b-=attact;
printf("AttactA=%d,HP_A=%d,HP_B=%d ",attact,hp_a,hp_b>0?hp_b:0);
flag=1;
}
else
{
attact=rand()%(16-6+1)+6;
hp_a-=attact;
printf("AttactB=%d,HP_A=%d,HP_B=%d ",attact,hp_a>0?hp_a:0,hp_b);
flag=0;
}
}
if(hp_a<=0)printf("****Aisdied**** ");
if(hp_b<=0)printf("****Bisdied**** ");
}