计算机c语言编程问题

 

#include <stdio.h>

void main()

{

float pg, yl, xj, jz;

float ss,st;

printf("请输入苹果、压力、香蕉、橘子的重量:");

scanf("%f %f %f %f",&pg,&yl,&xj,&jz);

ss = 2.50 * pg + 1.80 * yl + 1.60 * xj + 2.00 *jz;//总钱数

printf("应付%.2f元\n",ss);

printf("请输入客户实付金额:");

scanf("%f",&st);

printf("应找钱数:%.2f\n",st - ss);

}

#include <stdio.h>
/* 函数声明 */
float takeMoney(int, double);
	

int main()
{
    int type;		/* 水果品类:1苹果,2鸭梨,3香蕉,4橘子 */
    float appM, pearM, banM, orgM;		/* 水果的钱 */
    float weight;	/* 水果重量 */
    float inMoney;	/* 顾客给的钱 */
    float backMoney;	/* 找回去的钱 */
	float allMoney;	/* 总价 */
    printf("请输入苹果的重量:");
    scanf("%f", &weight);
    appM = takeMoney(1, weight);
    printf("请输入鸭梨的重量:");
    scanf("%f", &weight);
    pearM = takeMoney(2, weight);
    printf("请输入香蕉的重量:");
    scanf("%f", &weight);
    banM = takeMoney(3, weight);
    printf("请输入橘子的重量:");
    scanf("%f", &weight);
   	orgM = takeMoney(4, weight);
   	allMoney = appM+pearM+banM+orgM;
	printf("一共要付的钱数:%f \n\n", allMoney);
	printf("顾客的付款数:");
	scanf("%f", &inMoney);
	printf("\n应找回的钱数:%f", inMoney - allMoney);
	
	return 0;
}

float takeMoney(int type, double weight)
{
	double fruitMoney;
	switch (type){
		case 1:
			fruitMoney = 2.5 * weight;
			printf("苹果:%f 元\n\n", fruitMoney);
			break;
		case 2:
			fruitMoney = 1.8 * weight;
			printf("鸭梨:%f 元\n\n", fruitMoney);
			break;
		case 3:
			fruitMoney = 1.6 * weight;
			printf("香蕉:%f 元\n\n", fruitMoney);
			break;
		case 4:
			fruitMoney = 2.0 * weight;
			printf("橘子:%f 元\n\n", fruitMoney);
			break;
		default:
       		break;
	}
	return fruitMoney;
}

结果: