#include <stdio.h>

int main() { int fruitCode, weight; float price;

printf("请输入水果编号(1-4):");
scanf("%d", &fruitCode);

printf("请输入重量(单位:公斤):");
scanf("%d", &weight);

switch(fruitCode) {
    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;
}

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

return 0;

}

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

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

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