2. 苹果促销

【问题描述】

超市苹果打折促销,总重量如果不超过5斤,单价3元/斤,如果超过5斤,超过部分打八折;输入为所购买苹果的重量,输出为应付款的总额。

【样例输入1】

10

【样例输出1】

27

【样例输入2】

10.2

【样例输出2】

27.48

【源代码】

#include<iostream>
using namespace std;
int main(){
	double a,b,ans;
	cin>>a;
	b=a-5;
	//输入苹果的重量
	if(a<=5){//判断苹果质量是否大于5kg 
		ans=a*3;
	} else{
		ans=5*3+b*3*0.8;
	}
	//输出答案 
	cout << ans;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/chengjunming123/article/details/81099278
2.