我正在做一个班级作业(未评分),但不清楚为什么这段代码会导致我的程序“挂起”而不是通过循环运行。
#include <stdio.h>
#include <stdlib.h>
int main()
{
int nbStars = 0; // User defines the number of stars to display
int nbLines = 0; // User defines the number of lines on which to print
// Obtain the number of Stars to display
printf("Enter the number of Stars to display (1-3): ");
scanf("%d", &nbStars);
getchar();
// Limit the values entered to between 1 and 3
do {
printf("Enter the number of Stars to display (1-3): ");
scanf("%d", &nbStars);
if (nbStars < 1 || nbStars > 3) puts("\tENTRY ERROR: Please limit responses to between 1 and 3.\n");
} while (nbStars < 1 || nbStars > 3);
}