### 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)

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163`` `````` include include 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
 ``123`` ``````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.