gpt4 book ai didi

代码永远不会被执行 C

转载 作者:行者123 更新时间:2023-11-30 20:45:58 25 4
gpt4 key购买 nike

我在 if (knightATKC == 2 && KnightATKC == 4) i 说代码永远不会被执行的行上遇到了这个问题。它不会正常工作。如果有人知道如何解决这个问题那就太好了。不要担心您可能会看到的未使用的变量,我稍后会使用它,但现在我不知道如何修复代码永远不会被执行。抱歉我的英语不好:/

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>

int main()
{
char enter = 0;
char pNAME[30];
char pGENDER;
int pAGE;
int pATK;
int pHP = 20;
int pATKC;
int knightATK = 3;
int knightHP = 15;
int knightATKC = 0;
int kingATK = 5;
int kingHP = 30;
int kingATKC;

printf("While you are enjoying your breakfast at your house, suddenly you get teleported to a different dimension and no one to be seen except an old man.\n");
printf("\nOld Man: What is your name warrior?\n");
printf("\nInsert name:\n");
scanf("%s",pNAME);
fpurge( stdin );

printf("\nInsert gender (m/f):\n");
scanf("%c",&pGENDER);
fpurge( stdin );
while ( pGENDER != 'f' &&pGENDER != 'm' )
{
printf("\nInvalid entry, please try again.\n");
printf("\nInsert gender (m/f):\n");
scanf("%c",&pGENDER);
}

printf("\nOld Man: Now how old are you young warrior?\n");
printf("\nInsert Age:\n");
scanf("%d",&pAGE);
fpurge( stdin );
if ( pAGE < 18)
{
printf("\nOy mate! No stalker!\n");
printf("\nTeleporting back to reality...\n");

return 0;
}

if ( pAGE > 80)
{
printf("\nNo oldies allowed!\n");
printf("\nTeleporting back to reality...\n");

return 0;
}

printf("\nOld Man: Welcome warrior I fear the knights has taken over our kingdom, and you, %s, are the only one who can save us.\n",pNAME);
printf("\n%s: How am I suppose to do that?[Enter]\n",pNAME);
if (enter != '\r' && enter != '\n') { enter = getchar(); }
printf("HI");

while (pHP != 0 && knightHP != 0)
{
pATK = 5;
knightATK = 3;

knightATKC = ( rand()%5);

if (knightATKC == 2 && knightATKC == 4)
{
printf("The knight swings his sword at %s",pNAME);
printf("T\nhe knight hits %s for 3HP\n",pNAME);
pHP = pHP - 3;
}
else if (knightATKC == 3)
{
printf("\nThe knight slashes his sword at %s\n",pNAME);
printf("\nThe knight critically hit %s for 5 HP\n",pNAME);
pHP = pHP - 5;
}
else
{
printf("\nThe knight swings his sword at %s\n",pNAME);
printf("\nThe knight fails to hit %s\n",pNAME);
printf("\nPress [Enter] to attack\n");
}

}}

最佳答案

您的问题是不言自明的。 knightATKC == 2 && KnightATKC == 4 表示 knightATKC 同时为 2 和 4,这是不可能的。也许您的意思是 || ( bool 值或)而不是 && ( bool 值与)?

关于代码永远不会被执行 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32292420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com