检查用户输入的C语言是否为整数

时间:2019-11-13 21:26:39

标签: c

我有这个代码。我需要验证用户是否输入了整数,否则要求再次输入。

double num1, num2, num3, num4;
printf("Enter 1st number: \n");
scanf_s("%lf", &num1);

while (scanf_s("%lf", num1 != 2))
{
    while (getchar() != '\n');
    printf("It is not a digit, try again: \n");
}


printf("Enter 2nd number: \n");
scanf_s("%lf", &num2);

printf("Enter 3rd number: \n");
scanf_s("%lf", &num3);

printf("Enter 4th number: \n");
scanf_s("%lf", &num4);

0 个答案:

没有答案