-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch7-3.c
More file actions
36 lines (35 loc) · 1.02 KB
/
ch7-3.c
File metadata and controls
36 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<stdio.h>
int main() {
char mode;
int money;
while(printf("mode(A, B, C, D, or Q for exit):"),scanf("%c",&mode),mode!='Q'&&mode!='q') {
fflush(stdin);
if(!((mode>='A'&&mode<='D')||(mode>='a'&&mode<='d'))) {
printf("mode error\n");
continue;
}
printf("money:");
scanf("%d", &money);
double ans=0;
switch(mode){
case 'A':
case 'a':
ans+=(money>0?money*15/100.0:0)+(money>17850?(money-17850)*(28-15)/100.0:0);
break;
case 'B':
case 'b':
ans+=(money>0?money*13/100.0:0)+(money>23900?(money-23900)*(26-13)/100.0:0);
break;
case 'C':
case 'c':
ans+=(money>0?money*13/100.0:0)+(money>29750?(money-29750)*(26-13)/100.0:0);
break;
case 'D':
case 'd':
ans+=(money>0?money*14/100.0:0)+(money>14875?(money-14875)*(27-14)/100.0:0);
break;
}
printf("ans:%.2lf\n", ans);
fflush(stdin);
}
}