tax calculation float functions c ++

m a beginner programmer and I was to ask a program which calculates income tax based on a salary. Then to change the code and create below functions however I have no idea how to create them. these are:
float calculate_tax(float amount, float tax_rate);
float calculate_netpay(float amount, float tax);
float increment_salary(float amount, float increment_rate)

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
  include<stdio.h>
include<conio.h>


int main()


 {
     int employeeID = 0;
     float salary = 0;
     float taxtotal = 0;
     float netpaytotal = 0;
     char c = '-';
     char d[] = "Employee_Payroll";
     int j, k;
     char grade = 0;
     double inc1 = 0.025;
     double inc2 = 0.015;
     double inc3 = 0;
     double Y1tax;
     double Y2tax;
     double Y3tax;
     double Y4tax;
     double Y5tax;
     double netpay;
     double newpay;
     double newpay1;
     double newpay2;
     double newpay3;
     double newpay4;
     char inputChar = 'y';
     do
     {
         printf("Enter Employee ID: ");
         scanf_s("%d", &employeeID);
         printf("\n");
         if (employeeID == 1)
         {
             printf("Enter Salary: ");
             scanf_s("%f", &salary);
         }
         else
         {
             printf("Wrong Employee ID\n");
             exit(0);
         }
         printf("\n");
         if (salary >= 12000 && salary <= 15000)
         {
             for (j = 1; j <= 1; j++)
             {
                 for (k = 1; k <= 34; k++)
                 {
                     printf("%c", c);
                 }
                 printf("\n");
                 {
                     printf("-------Employee Payroll-----------\n");
                 }
             }
             printf("\n");
             printf("Employee ID: %d\n", employeeID);
             printf("Gross Salary: %f\n", salary);
             taxtotal = salary * 0.25;
             printf("Tax: %f\n", taxtotal);
             netpaytotal = salary - taxtotal;
             printf("Net Pay: %f\n", netpaytotal);
         }
         else
         {
             printf("Error: Salary %f is out of range!!!\n", salary);
             exit(0);
         }
         printf("\n");
         if (salary >= 12000 && salary <= 15000 && employeeID == 1)
             for (j = 1; j <= 1; j++)
             {
                 for (k = 1; k <= 34; k++)
                 {
                     printf("%c", c);
                 }
             }
         printf("\n");
         {
             printf("Enter Grade: %c", grade);
             "\n";
             scanf_s(" %c", &grade, 1);
         }
         printf("\n");
         switch (grade)
         {
         case 'A':
             printf("The increment is: %f\n", inc1);
             printf("Increment and tax over the five years\n");
             newpay = (salary * 0.025) + salary;
             Y1tax = newpay * 0.25;
             netpay = newpay - Y1tax;
             printf("Year 1: tax = %f, net pay = %f\n", Y1tax, netpay);
             newpay1 = (newpay * 0.025) + newpay;
             Y2tax = newpay1 * 0.25;
             netpay = newpay1 - Y2tax;
             printf("Year 2: tax = %f, net pay = %f\n", Y2tax, netpay);
             newpay2 = (newpay1 * 0.025) + newpay1;
             Y3tax = newpay2 * 0.25;
             netpay = newpay2 - Y3tax;
             printf("Year 3: tax = %f, net pay = %f\n", Y3tax, netpay);
             newpay3 = (newpay2 * 0.025) + newpay2;
             Y4tax = newpay3 * 0.25;
             netpay = newpay3 - Y4tax;
             printf("Year 4: tax = %f, net pay = %f\n", Y4tax, netpay);
             newpay4 = (newpay3 * 0.025) + newpay3;
             Y5tax = newpay4 * 0.25;
             netpay = newpay4 - Y5tax;
             printf("Year 5: tax = %f, net pay = %f\n", Y5tax, netpay);
             break;
         case 'B':
             printf("The increment is: %f\n", inc2);
             printf("Increment and tax over the five years\n");
             newpay = (salary * 0.015) + salary;
             Y1tax = newpay * 0.25;
             netpay = newpay - Y1tax;
             printf("Year 1: tax = %f, net pay = %f\n", Y1tax, netpay);
             newpay1 = (newpay * 0.015) + newpay;
             Y2tax = newpay1 * 0.25;
             netpay = newpay1 - Y2tax;
             printf("Year 2: tax = %f, net pay = %f\n", Y2tax, netpay);
             newpay2 = (newpay1 * 0.015) + newpay1;
             Y3tax = newpay2 * 0.25;
             netpay = newpay2 - Y3tax;
             printf("Year 3: tax = %f, net pay = %f\n", Y3tax, netpay);
             newpay3 = (newpay2 * 0.015) + newpay2;
             Y4tax = newpay3 * 0.25;
             netpay = newpay3 - Y4tax;
             printf("Year 4: tax = %f, net pay = %f\n", Y4tax, netpay);
             newpay4 = (newpay3 * 0.015) + newpay3;
             Y5tax = newpay4 * 0.25;
             netpay = newpay4 - Y5tax;
             printf("Year 5: tax = %f, net pay = %f\n", Y5tax, netpay);
             break;
         case 'C':
             printf("The increment is: %f\n", inc3);
             printf("Increment and tax over the five years\n");
             int i = 1;
             while (i <= 5)
             {
                 printf("Year %d: tax = %f, net pay = %f\n", i, taxtotal, netpaytotal);
                 i = i + 1;
             }
         default: printf("Invalid grade\n");
         }
         char inputChar;
         printf("Do you want to continue (y/n)?: ");
         inputChar = _getch();
         printf("%c\n", inputChar);
         while ((inputChar != 'Y' && inputChar != 'y') && (inputChar != 'N' && inputChar != 'n'))
         {
             printf("Please enter y or n: ");
             inputChar = _getch();
             printf("%c\n", inputChar);
         }
     } 
    
 while (inputChar == 'y');
Last edited on
> create below functions however I have no idea how to create them
here you are
1
2
3
float calculate_netpay(float amount, float tax){
   return 42;
}
For code that is supposed to be C++ it sure looks suspiciously like almost unadulterated C. The non-standard _getch function spoils the purity.

change the code and create below functions however I have no idea how to create them
A couple of lessons on functions might be something to help then:

https://www.learncpp.com/cpp-tutorial/introduction-to-functions/

(Reading at least the first six parts of Chapter 2 would be a very good start. Well, really helpful only if the code is C++, not C)
Registered users can post here. Sign in or register to post.