我的程序是一个简单的“石头剪刀布蜥蜴 Spock”程序,我想添加 2 人或 1 人与计算机选项。这就是我编码选择部分的方式:
printf("1.One player OR 2.Two players?\n");
scanf("%d", playerNum);
//input section
printf("1.rock\n2.paper\n3.scissor\n4.spock\n5.lizard\n");
printf("player A enter a choice ");
scanf ("%d", &choiceA);
if (playerNum == 2)
{
printf("1.rock\n2.paper\n3.scissor\n4.spock\n5.lizard\n");
printf("player B enter a choice ");
scanf ("%d", &choiceB);
}
else if (playerNum == 1)
{
choiceB = 1+rand()%5;
printf("The computer has picked %d", choiceB);
}
当我运行程序时,它在我输入playerNum
.
上面使用的所有变量都声明为整数。