// ex_ch7_7.c
#include <stdio.h>

const float BASIC_RATE = 10.0;
const float PAY_FIRST = 300.0;
const float PAY_SECOND = 150.0;
const float TAX_FIRST = 0.15;
const float TAX_SECOND = 0.20;
const float TAX_REST = 0.25;
const int OVERTIME_START = 40;
const float OVERTIME_MULTI = 1.5;

int main(void)
{
	int hours_worked;
	int overtime = 0;
	float overtime_hours, overall_hours, gross_pay;
	float taxes = 0;
	float rest;

	printf("Enter the number of hours you worked: ");
	scanf("%d", &hours_worked);

	if (hours_worked >= OVERTIME_START)
	{
		overtime = hours_worked - OVERTIME_START;
	}
	overtime_hours = overtime * OVERTIME_MULTI;
	// all what should be paid
	overall_hours = hours_worked + overtime_hours;

	gross_pay = overall_hours * BASIC_RATE;
	printf("Gross pay $%.2f\n", gross_pay);

	if (gross_pay <= PAY_FIRST)
	{
		taxes = gross_pay * TAX_FIRST;
	}
	else if (gross_pay > PAY_FIRST && gross_pay <= PAY_FIRST + PAY_SECOND)
	{
		taxes = PAY_FIRST * TAX_FIRST;
		rest = gross_pay - PAY_FIRST;
		taxes += rest * TAX_SECOND;
	}
	else
	{
		// calculate the base tax
		taxes = PAY_FIRST * TAX_FIRST;
		// add the secondary tax which is always 150
		taxes += PAY_SECOND * TAX_SECOND;
		// calculate the rest, which is over 450 and get the tax
		rest = gross_pay - (PAY_FIRST + PAY_SECOND);
		taxes += rest * TAX_REST;
	}
	// output what we got
	printf("Taxes $%.2f\n", taxes);
	printf("Net pay $%.2f\n", gross_pay - taxes);

	return 0;
}