9: 门票价格计算

9 门票价格计算

作者: Turbo 时间限制: 1S 章节: 分支结构

问题描述 :
某旅游景点门票价格为每人5元。但团体可以优惠,分为以下情况:
人数超过20,则所有人优惠10%;
人数超过40,则所有人优惠15%;
人数超过80,则所有人优惠20%;
人数超过120,则所有人优惠30%。
请跟据团体的人数,求出该团体的总门票价格。

输入说明 :
输入一个整数i(0≤i≤1,000),表示一个团体的总人数。在行首和行尾没有多余的空格。

输出说明 :
输出一个实数,即该团体需要支付的总票价,精确到小数点后2位。在行首和行尾不要输出多余的空格。

输入范例 :
80
输出范例 :
340.00
代码:

#include <stdio.h>
int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		if (n > 120)
		{
			printf("%.2f", (float)n * 5 * 0.7);
		}
		else if (n > 80)
		{
			printf("%.2f", (float)n * 5 * 0.8);
		}
		else if (n > 40)
		{
			printf("%.2f", (float)n * 5 * 0.85);
		}
		else if (n > 20)
		{
			printf("%.2f", (float)n * 5 * 0.9);
		}
		else
		{
			printf("%.2f", (float)n * 5 );
		}
	}
	return 0;
}
Yesterday is history,tomorrow ismystery,but today is a gift!That why it is called Present!
原文地址:https://www.cnblogs.com/VictorierJwr/p/12242188.html