【发布时间】:2020-04-11 11:03:54
【问题描述】:
我也尝试过添加 fflush(stdout);在 printf 语句之后并没有做任何事情,在 scanf 之前也没有使用 fflush(stdin)
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
float cost(int qty)
{
if (qty <= 20)
return qty * 23.45;
if (qty >= 21 && qty <= 100)
return qty * 21.11;
if (qty > 100)
return qty * 18.75;
return '0';
}
// void main() VS Only
int main()
{
int q;
printf("Enter quantity of books wanted: ");
scanf("&d", &q);
printf("\n\nThe total cost for purchasing books is: $%0.2f\n\n", cost(q));
}
【问题讨论】:
-
您观察到哪些不正确的行为?给出准确的输入、预期行为和实际行为。
-
#include <conio.h>添加这个 -
注意:
return '0';可能不会像您认为的那样做。 ITYMreturn 0;. -
Renatus,最大的错误是没有完全启用警告。省时间。全部启用。
scanf("&d", &q);应该收到警告,例如“警告:格式 [-Wformat-extra-args] 的参数过多”/