这是我的代码:
printf("The current number is %d. Player 2, enter a factor.\n", number);
scanf("%d", &factor);
while (number % factor != 0) {
//check if factor or not, but use "while" so it doesn't go all the way back to the start of loop
printf("Invalid factor. %d does not evenly divide %d. Enter a valid factor.\n", factor, number);
printf("The current number is %d. Player 2, enter a factor.\n", number);
scanf("%d", factor);
}
while (factor == 1){
printf("Invalid factor. Numbers less than 2 are not allowed.\n");
printf("The current number is %d. Player 2, enter a factor.\n", number);
scanf("%d", factor);
}
number = (number / factor); // same dealio as before
x += 1; // if the game doesn't end, it's player 1's turn
}
当我为播放器2输入无效因子,然后输入有效因子时,程序停止响应。有人可以解释一下原因吗?
例如,如果初始数字是20,则播放器1输入6,并且给出正确的错误并且循环重复直到它们给出有效因子,例如5.然后程序进展到播放器2.当前的数字是现在是4,但是玩家2输入6,并且被引导到循环直到他们选择2或4.然而,在选择有效因子时,程序停止响应。我不知道为什么。
这些变量都已声明,它们只是被裁剪掉了,因为这个帖子大部分都不是代码。