#include <stdio.h>
#include <stdlib.h>
//Always use MACROS to define constants.
#define MAX_EMPLOYEE 5
#define MAX_NAME_LEN 50

//You can name function parameters same as local vairables because they have different scopes so they wont collide.
void Prompt(char** name, float* rate, float* hours)
{
	for (int i = 0, j = 0; i < MAX_EMPLOYEE; i++, j++)
	{
		printf("Enter name: ");
		scanf("%s", name + (i + j));

		printf("Enter hourly rate: ");
		scanf("%f", rate + i);
		if (rate[i] == -1)
		{
			break;
		}

		printf("Enter hours worked: ");
		scanf("%f", hours + i);
		if (hours[i] == -1)
		{
			break;
		}
	}
	//return; No need to return here.
}

void GrossPay(float* grosspay, float* basepay, float* overtimepay, float* rate, float* hours)
{
	for (int i = 0; i < MAX_EMPLOYEE; i++)
	{
		if (hours[i] > 40)
		{
			overtimepay[i] = (hours[i] - 40) * (rate[i]) * 1.5;
			basepay[i] = rate[i] * hours[i];
			grosspay[i] = rate[i] * hours[i] + (hours[i] - 40) * (rate[i]) * 1.5;

		}

		else
		{
			overtimepay[i] = 0;
			basepay[i] = rate[i] * (hours[i]);
			grosspay[i] = basepay[i];

		}
	}

	//return; No need to return from void function.
}

//When passing array as arguments use arr* instead of arr[]
void* Taxes(float* taxes_owed, float* gross_pay)
{
	for (int i = 0; i < MAX_EMPLOYEE; i++)
	{
		taxes_owed[i] = 0.2 * gross_pay[i];
	}
	//return taxes_owed; //you cannot return 5 tax values either return single value or whole array containing those values.
}

float CalculateTotal(float* gross_pay)
{
	float total_pay = 0.0f;//0.0f for floats only.

	for (int i = 0; i < MAX_EMPLOYEE; i++)
	{
		total_pay += gross_pay[i];
	}

	return total_pay;
}

void PrintOutput(char** first_name, float* rate, float* hours, float* gross_pay, float* base_pay, float* overtime_pay, float* taxes_owed, float* net_pay, float total_pay)
{
	for (int i = 0, j = 0; i < MAX_EMPLOYEE; i++, j++)
	{
		printf("\nPay to: %s\n", first_name + (i + j));
		printf("Hours worked: %5.1f\n", hours[i]);
		printf("Hourly rate: $%5.2f\n", rate[i]);
		printf("Gross pay: $%5.2f \n", gross_pay[i]);
		printf("Base pay: $%5.2f \n", base_pay[i]);
		printf("Overtime pay: $%5.2f\n", overtime_pay[i]);
		printf("Taxes paid: $%5.2f\n", taxes_owed[i]);
		printf("Net pay: $%5.2f\n\n", net_pay[i]);
	}
	printf("Total paid to all employees= $%5.2f\n", total_pay);
}

int main()
{
	char first_name[MAX_EMPLOYEE][MAX_NAME_LEN] = { NULL };
	float rate[MAX_EMPLOYEE] = { 0.0f };
	float hours[MAX_EMPLOYEE] = { 0.0f };
	float gross_pay[MAX_EMPLOYEE] = { 0.0f };
	float base_pay[MAX_EMPLOYEE] = { 0.0f };
	float overtime_pay[MAX_EMPLOYEE] = { 0.0f };
	float taxes_owed[MAX_EMPLOYEE] = { 0.0f };
	float net_pay[MAX_EMPLOYEE] = { 0.0f };
	float total_pay = 0.0f;

	Prompt(first_name, rate, hours);
	GrossPay(gross_pay, base_pay, overtime_pay, rate, hours);
	Taxes(taxes_owed, gross_pay);

	total_pay = CalculateTotal(gross_pay);

	for (int i = 0; i < MAX_EMPLOYEE; i++)
		net_pay[i] = gross_pay[i] - taxes_owed[i];

	PrintOutput(first_name, rate, hours, gross_pay, base_pay, overtime_pay, taxes_owed, net_pay, total_pay);
	return 0;
}
