用c++编写程序,输入上网的时间计算上网费用,计算的方法如下: 【25元 <10小时 费用 =每小时 2.5元 10~50小时 [每小时2元 ≥50小时 同时,为了鼓励多上网,每月收费最多不超过 130元。 要求:使用 switch 语句编程。
时间: 2023-05-31 21:02:21 浏览: 104
#include <stdio.h>
int main() {
int hours;
float fee;
printf("请输入上网时间(小时):");
scanf("%d", &hours);
switch (hours) {
case 0:
fee = 0;
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
fee = hours * 2.5;
break;
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:
case 31:
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:
case 47:
case 48:
case 49:
case 50:
fee = hours * 2;
break;
default:
fee = 50 * 2 + (hours - 50) * 1.5;
break;
}
if (fee > 130) {
fee = 130;
}
printf("上网费用为:%.2f元\n", fee);
return 0;
}
阅读全文