#include
#include
#include
#define ID 1
#define ID1 2
#define ID2 3
#define ID3 4
struct human
{
int blood;
int state;//状态
int rate;
};
int num=0; //回合数
struct human one={400,0,50};
struct human two={400,0,50};
struct human three={400,0,50};
struct human four={400,0,50};
void show(struct human h)
{
printf("第%d回合\n角色%d 体力%d %s 回复率%d%\n",++num,ID,h.blood,h.state?"正常":"中毒",h.rate);
}
void show1(struct human h1)
{
printf("\n角色%d 体力%d %s 回复率%d%%\n",ID1,h1.blood,h1.state?"正常":"中毒",h1.rate);
}
void show2( struct human h2)
{
printf("\n角色%d 体力%d %s 回复率%d%%\n",ID2,h2.blood, (h2.state ? "中毒":"正常"),h2.rate);
}
void show3(struct human h3)
{
printf("\n角色%d 体力%d %s 回复率%d%%\n",ID3,h3.blood,h3.state?"正常":"中毒",h3.rate);
}
int main()
{
char ch;
srand( (unsigned)time( NULL ) );
show(one);
show1(two);
show2(three);
show3(four);
while(ch=getchar())
{
if(ch==10)
{
int r=rand();
if(r>16384)
{
one.state=1;
one.blood=one.blood-r/100;
if(one.blood<=0)
{
one.blood=0;
}
}
else one.state=0;
show(one);
if(r<16384)
{
two.state=1;
two.blood=two.blood-r/130;
if(two.blood<=0)
{
two.blood=0;
}
}
else two.state=0;
show1(two);
if(r>16384)
{
three.state=1;
three.blood=three.blood-r/105;
if(three.blood<=0)
{
three.blood=0;
}
}
else three.state=0;
show2(three);
if(r<16384)
{
four.state=1;
four.blood=four.blood-r/150;
if(four.blood<=0)
{
four.blood=0;
show3(four);
return 0;
}
}
else four.state=0;
show3(four);
}
}
return 0;
}
你的程序我基本上看懂了,上面的代码能够正常执行
1.c语言不支持bool类型,所以定义state时,应该定义成int state
2.char ch,应该写在函数前面,因为c语言不支持变量的随定义随引用(即如果要使用一个变量,只需先写一定义变量的语句即可,并不需要在函数开头定义)
3.c语言不支持引用类型,引用是c++增加的特性
void show(human &h)
应该写成void show( struct human h)
4.较低版本的c语言不支持直接使用自定义的结构体类型定义变量,结构体类型前还需要加struct关键字 如human one是不行的,必须是struct human one
指针木有初始化。。