Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define BASIC_PAY_RATE_ONE 8.75
- #define BASIC_PAY_RATE_TWO 9.33
- #define BASIC_PAY_RATE_THREE 10.00
- #define BASIC_PAY_RATE_FOUR 11.20
- #define EXCESS 40.0
- #define OVERTIME 1.5
- #define FIRST_BORDER 300.00
- #define NEXT_BORDER 150.00
- #define SECOND_BORDER (FIRST_BORDER + NEXT_BORDER)
- #define TAX_RATE_ONE 0.15
- #define TAX_RATE_TWO 0.20
- #define DIFFERENCE_BETWEEN_TAX_RATE_TWO_AND_TAX_RATE_ONE (TAX_RATE_TWO - TAX_RATE_ONE)
- #define TAX_RATE_THREE 0.25
- #define DIFFERENCE_BETWEEN_TAX_RATE_THREE_AND_TAX_RATE_TWO (TAX_RATE_THREE - TAX_RATE_TWO)
- int get_num_decision(void);
- double get_basic_pay_rate(int num_decision);
- double get_additional_pay_rate(double basic_pay_rate);
- double get_non_negative_not_too_big(void);
- double gross_pay_calc(double hours, double basic_pay_rate, double additional_pay_rate);
- double the_taxes_calc(double gross_pay);
- void response_output(double gross_pay, double the_taxes);
- int main(void) {
- int num_decision = 0;
- double basic_pay_rate = 0, additional_pay_rate = 0;
- double hours = 0, gross_pay = 0, the_taxes = 0;
- while ((num_decision = get_num_decision()) != 5) {
- basic_pay_rate = get_basic_pay_rate(num_decision);
- additional_pay_rate = get_additional_pay_rate(basic_pay_rate);
- hours = get_non_negative_not_too_big();
- gross_pay = gross_pay_calc(hours, basic_pay_rate, additional_pay_rate);
- the_taxes = the_taxes_calc(gross_pay);
- response_output(gross_pay, the_taxes);
- }
- return 0;
- }
- int get_num_decision(void) {
- printf("Enter the number corresponding to the desired pay rate or action:\n");
- printf("1) $%.2f/hr\n", BASIC_PAY_RATE_ONE);
- printf("2) $%.2f/hr\n", BASIC_PAY_RATE_TWO);
- printf("3) $%.2f/hr\n", BASIC_PAY_RATE_THREE);
- printf("4) $%.2f/hr\n", BASIC_PAY_RATE_FOUR);
- printf("5) quit\n\n");
- int num = 0;
- int num_decision = 0;
- while (((num = scanf("%d", &num_decision)) != 1) || (num_decision > 5) || (num_decision < 1)) {
- if ((num == EOF) || (num == 0))
- exit(EXIT_SUCCESS);
- printf("You were mistaken\n"
- "Enter the value greater than or equal to 1\n"
- "And less than or equal to 5: ");
- }
- while((num = getchar()) != '\n')
- if (num == EOF)
- exit(EXIT_SUCCESS);
- return num_decision;
- }
- double get_basic_pay_rate(int num_decision) {
- switch (num_decision) {
- case 1 : return BASIC_PAY_RATE_ONE;
- case 2 : return BASIC_PAY_RATE_TWO;
- case 3 : return BASIC_PAY_RATE_THREE;
- case 4 : return BASIC_PAY_RATE_FOUR;
- default : exit(EXIT_SUCCESS);
- }
- }
- double get_additional_pay_rate(double basic_pay_rate) {
- return basic_pay_rate * OVERTIME - basic_pay_rate;
- }
- double get_non_negative_not_too_big(void) {
- int num = 0;
- double hours = 0;
- printf("\nEnter the hours worked in a week: ");
- while (((num = scanf("%lf", &hours)) != 1) || (hours < 0) || (hours > 168)) {
- if ((num == EOF) || (num == 0))
- exit(EXIT_SUCCESS);
- printf("You were mistaken\n"
- "Enter the value greater than or equal to 0\n"
- "And less than or equal to 168: ");
- }
- while ((num = getchar()) != '\n')
- if (num == EOF)
- exit(EXIT_SUCCESS);
- return hours;
- }
- double gross_pay_calc(double hours, double basic_pay_rate, double additional_pay_rate) {
- double gross_pay = hours * basic_pay_rate;
- if (hours > EXCESS)
- gross_pay += (hours - EXCESS) * additional_pay_rate;
- return gross_pay;
- }
- double the_taxes_calc(double gross_pay) {
- double the_taxes = gross_pay * TAX_RATE_ONE;
- if (gross_pay > FIRST_BORDER)
- the_taxes += (gross_pay - FIRST_BORDER) * DIFFERENCE_BETWEEN_TAX_RATE_TWO_AND_TAX_RATE_ONE;
- if (gross_pay > SECOND_BORDER)
- the_taxes += (gross_pay - SECOND_BORDER) * DIFFERENCE_BETWEEN_TAX_RATE_THREE_AND_TAX_RATE_TWO;
- return the_taxes;
- }
- void response_output(double gross_pay, double the_taxes) {
- printf("\nGross pay: %.2f\n", gross_pay);
- printf("The taxes: %.2f\n", the_taxes);
- printf("Net pay: %.2f\n\n", gross_pay - the_taxes);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement