Онлайн компилятор C

#include <stdio.h> int main() { int price,items,discount; float total_price,total_discount; scanf("%d%d%d",price,items,discount); total_price = items * discount; total_discount = (total_price/100) * discount; total_price = total_price - total_discount; printf("C=%d",total_price); return 0 }
这段代码试图计算商品的总价和折扣,但存在几个问题。

- 代码中 `scanf` 缺少取地址符 `&`,导致输入无法正确存储到变量中。
- 计算逻辑有误:`total_price` 被赋值为 `items * discount`,但 `discount` 是折扣率,应该乘以单价而不是折扣。同时 `total_discount` 的计算也使用了错误的变量。
- `printf` 中格式说明符 `%d` 与 `total_price` 的类型 `float` 不匹配,应使用 `%f`。
- 最后缺少分号。

- 检查 `scanf` 中每个变量前是否都加了 `&`。
- 重新思考折扣计算:通常总价是单价乘以数量,折扣是总价乘以折扣率,最后总价减去折扣。注意变量名 `price` 可能代表单价,但代码中未使用。