这真的很奇怪,我尝试过但找不到。当我调用Goblin函数时,它会像这样两次打印printf语句
绿色妖精投掷了一个幽灵炸弹!
绿色妖精派出剃须刀!
请帮助我,我不知道该如何解决,我修复了蜘蛛侠,但是妖精仍然打印两次; _;
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
enum MoveS
{
Move1=6,Move2=9,Move3=10
};
enum MoveG
{
Move4=5,Move5=7,Move6=13
};
int spiderManAttacks(); //prototype
int greenGoblinAttacks(); //protoype
void printEnergies(); //prototype
int main()
{
int spiderManEnergy=100;
int greenGoblinEnergy=100;
int moveSpiderMan,moveGreenGoblin;
int rateS;
srand(time(NULL));
printf("Battle begins!!!");
do{
rateS=rand()%100+1;
spiderManAttacks(rateS,greenGoblinEnergy);
greenGoblinEnergy-=(spiderManAttacks(moveSpiderMan));
printEnergies(greenGoblinEnergy,spiderManEnergy);
greenGoblinAttacks(spiderManEnergy);
spiderManEnergy-=(greenGoblinAttacks(moveGreenGoblin));
printEnergies(greenGoblinEnergy,spiderManEnergy);
}while(0<spiderManEnergy && 0<greenGoblinEnergy);
printf("\nBattle ends!!");
if(greenGoblinEnergy<spiderManEnergy)
printf("\nSpider-Man wins! Yeah Spidey rules!");
else if(spiderManEnergy<greenGoblinEnergy)
printf("\nGreen Goblin won! Yeah Jack-o'-lanterns! ");
return 0;
}
int spiderManAttacks(int rateS,int greenGoblinEnergy)
{
enum MoveS moveSpiderMan;
if(1<=rateS && rateS<=45)
{
printf("\nSpider-Man uses spider-sense!");
moveSpiderMan=Move1;
}
else if(46<=rateS && rateS<=85)
{
printf("\nSpider-man shoots spider web!");
moveSpiderMan=Move2;
}
else if(86<=rateS && rateS<=100)
{
printf("\nSpider-Man uses super agility and speed!");
moveSpiderMan=Move3;
}
return moveSpiderMan;
}
int greenGoblinAttacks(int spiderManEnergy)
{
int rateG;
rateG=rand()%100+1;
enum MoveG moveGreenGoblin;
if(1<=rateG&&rateG<=45)
{
printf("\nGreen Goblin throws a jack-o-'lantern!");
moveGreenGoblin=Move4;
}
else if(46<=rateG&&rateG<=85)
{
printf("\nGreen Goblin sends out razor bats!");
moveGreenGoblin=Move5;
}
else if(86<=rateG&&rateG<=100)
{
printf("\nGreen Goblin throws a ghost bomb!");
moveGreenGoblin=Move6;
}
return moveGreenGoblin;
void printEnergies(int greenGoblinEnergy,int spiderManEnergy)
{
printf("\nGoblin %d Spider-man %d",greenGoblinEnergy,spiderManEnergy);
}
请帮助我