所以我写这个程序是一个两人玩剪刀石头布的游戏,无论每个玩家选择什么,输出都是“玩家 1 获胜”。
#include <stdio.h>
int main(void)
{
long player1Choice, player2Choice, p, r, s;
printf("Player 1, enter paper (p), rock (r), or scissors (s)\n");
player1Choice=getchar();
getchar();
printf("Player 2, enter paper (p), rock (r), or scissors (s)\n");
player2Choice=getchar();
getchar();
if((player1Choice=p)&&(player2Choice=r))
printf("Player 1 wins!\n");
else if((player1Choice=r)&&(player2Choice=p))
printf("Player 2 wins!\n");
else if((player1Choice=r)&&(player2Choice=s))
printf("Player 1 wins!\n");
else if((player1Choice=s)&&(player2Choice=r))
printf("Player 2 wins!\n");
else if((player1Choice=s)&&(player2Choice=p))
printf("PLayer 1 wins!\n");
else if((player1Choice=p)&&(player2Choice=s))
printf("Player 2 wins!\n");
printf("Press any key to exit");
getchar();
return 0;
}
我认为我的“if”语句中的逻辑“and”可能会造成麻烦,但我不确定。