在线编译器 C

#include <stdio.h> int main() { int price,items,discount; float total_price, total_discount; scanf("%d%d%d",&price,&items,&discount); total_price = price * items; total_discount = (total_price / 100) * discount; total_price = total price - total_discount; printf("C=%.2f\n",total_price); return 0; }
这段代码的目的是计算商品的总价并应用折扣。它从用户输入中读取单价、数量和折扣百分比,然后计算折扣后的总价并输出。

代码中存在一个语法错误,导致无法编译。

- 在第9行,`total price` 中间有一个空格,这是不合法的。C语言中变量名不能包含空格,应该使用下划线或直接连写,比如 `total_price`。
- 注意变量命名的一致性:前面已经定义了 `total_price`,后面使用时必须保持完全相同的写法。