Home > Back-end >  And buffer, C Primer Plus fifth edition chapter 8 programming practice number 7
And buffer, C Primer Plus fifth edition chapter 8 programming practice number 7

Time:05-11

 1/* input working hours in a week, then print the total wages, taxes, and net pay, */
2 # include & lt; stdio.h>
3 # define 40//more than 40 hours for overtime HOUR
4 # define HOURRATE/1.5/more than 40 hours over multiple
5 # define RATE1/0.15/$300 before the tax rate shall be 15%
6 # define RATE2/0.20/under a $150 tax rate of 20%
7 # define RATE3/0.25/25% for the rest of the
300//8 # define BREAK1 cut-off rate of the first
9 # define BREAK2 at 450//the second cut-off point
10 # define BASE1 (BREAK1 * RATE1)//salary is $300 tax payable
11 # define BASE2 (BASE1 + (BREAK2 - BREAK1) * RATE2)//salary is $450 tax payable
12 void menu (void);
13 char get_first (void);
14
15 int main (void)
16 {
17 double wage;//total wages
18 double tax;//tax
19 double netwage;//net pay
Double 20 hours;//this week working hours
21 double WAGE_HOUR;//hourly wage
22 char ch;
23 int the done=0;
24
While 25 (done==0)
26 {
27 the menu ();
28 get_first ();
29 the switch (ch)
30 {
31 case 'a' : WAGE_HOUR=8.75;
32 break;
33 case 'b' : WAGE_HOUR=9.33;
34 break;
35 case 'c' : WAGE_HOUR=10.00;
36 break;
37 case 'd' : WAGE_HOUR=11.20;
38 break;
39 case 'e' : done=1;
40 break;
41 default: printf (" both Please enter a number from a to e. \ n ");
42 the continue;
43}
44
45 the if (done==0)
46 {
47 printf (" How long did you work this week? \n");
48 the scanf (" % lf ", & amp; Hours);
49 if (pump & lt;=HOUR)
Wage=50 hours * WAGE_HOUR;
51 the else
52 wage=HOUR * HOURRATE WAGE_HOUR + (hours - HOUR) * * WAGE_HOUR;
53 the if (wage & lt;=BREAK1)
54 tax=wage * RATE1;
55 else if (wage & lt;=BREAK2)
56 tax=BASE1 + (wage - BREAK1) * RATE2;
57 the else
58 tax=BASE2 + (wage - BREAK2) * RATE3;
59 netwage=wage - tax;
60 printf (" Your total wage is % lf dollars. \ n ", wage);
61 printf (" Your tax is % lf dollars. \ n ", tax);
62 printf (" Your netwage is % lf dollars. \ n ", netwage);
63 the continue;
64}
65 else
66 break;
67}
68 printf (" Done! \n");
69
70 return 0;
71}
72
73 void menu (void)
74 {
75 printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
76 printf (" Enter the number corresponding to the desired pay rate or action: \ n ");
$8.75/hr 77 printf (" a) b) $9.33/hr \ n ");
78 printf (" c) $10.00/hr d) $11.20/hr \ n ");
79 printf (e) the quit "\ n");
80 printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
81}
82
83 char get_first (void)
84 {
85 int ch;
86
While 87 ((ch=getchar ())! )
='\ n'88 {
89 the if (ch & lt; 33)
90 the continue;
91 else
92 break;
93}
94
95 return ch;
96}

CodePudding user response:

Press f will jump out of the two menu, and press e can't quit
  • Related