【发布时间】:2021-10-20 17:55:03
【问题描述】:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main() {
double NET_Income = 9999.58;
printf("Enter your NET monthly income: ");
scanf("%f", &NET_Income);
while (NET_Income < 500.00) OR (NET_Income > 400000.00); {
printf("Sorry, that is an incorrect amount, please re-enter your NET monthly income: ");
scanf("%f", &NET_Income);
}
return 0;
}
当我尝试在 Visual Studio 中运行此代码时,出现以下错误:
忽略返回值:'scanf'
警告 C4477 'scanf':格式字符串 '%f' 需要一个类型为“float *”的参数,但可变参数 1 的类型为“double *”
警告 C4013 'OR' 未定义;假设 extern 返回 int
'scanf' : format string '%f' requires an argument of type 'float *', but variadic argument 1 has type 'double *
【问题讨论】:
-
C 中没有
OR运算符,它是||。 -
double的格式运算符是%lf,而不是%f。 -
改用
%lf -
有
or每<iso646.h>... -
它是 C,而不是 Python。