#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;

}

水果价格计算器:苹果、梨、桔子、芒果单价查询及付款金额计算

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

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