[CSP-J2019] 加工零件 c++代码
时间: 2023-08-29 21:07:05 浏览: 197
以下是一个简单的 C 代码示例,用于计算加工零件的成本:
```
#include <stdio.h>
int main() {
float material_cost, labor_cost, total_cost;
int num_parts;
printf("Enter the cost of materials per part: ");
scanf("%f", &material_cost);
printf("Enter the cost of labor per part: ");
scanf("%f", &labor_cost);
printf("Enter the number of parts to be produced: ");
scanf("%d", &num_parts);
total_cost = material_cost + labor_cost;
printf("The total cost per part is: $%.2f\n", total_cost);
total_cost *= num_parts;
printf("The total cost for %d parts is: $%.2f\n", num_parts, total_cost);
return 0;
}
```
这个程序会要求用户输入每个零件的材料成本和人工成本,以及要生产的零件数量。然后,它会计算每个零件的总成本和所有零件的总成本,并将结果打印到屏幕上。
阅读全文