#include <stdio.h>

int main() { int fruit_code; // 水果编号 float weight; // 重量 float price; // 单价 float total_price; // 总价

printf("请输入水果编号(1-4): ");
scanf("%d", &fruit_code);
printf("请输入重量(单位: 公斤): ");
scanf("%f", &weight);

switch(fruit_code) {
    case 1:
        price = 2.0;
        break;
    case 2:
        price = 2.5;
        break;
    case 3:
        price = 3.0;
        break;
    case 4:
        price = 4.5;
        break;
    default:
        printf("输入错误\n");
        return 0;
}

total_price = price * weight;
printf("应付款: %.2f元\n", total_price);

return 0;

}

以下4种水果1苹果2梨3桔子4芒果单价分别是20元公斤25元公斤30元公斤45元公斤请输入水果编号、重量计算应付款 用c语言

原文地址: http://www.cveoy.top/t/topic/Jq0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录