#include <iostream.h>
#include <stdio.h>
#include <iomanip.h>
#include <cstdlib>
main()
{

        int numberofemployees,grade[100], employeenumber[100], totalhours[100], c=0, overtime[100], hours[100], d=0, e=0, f=0;
	float rate[100], grosspay[100], super[100], netpay[100], taxrate[100], tax[100], percent;
	char null, invalidgrade, invalidhours, q, numberused;

        system("cls");
	cout << "--------------------------------------"<<endl;
	cout << "| Joseph's weekly payroll calculator |"<<endl;
	cout << "--------------------------------------"<<endl<<endl<<endl;
	cout << "Please enter the number of employees >";
        cin >> numberofemployees;
//        std::cin.clear();
        
        system("cls");
        c=0;
        for(;c<numberofemployees;)
	{

           percent=(float)(c+1)/numberofemployees*100;
           cout <<endl<<"|";
           f=0;
           for(;f<(7.7*(percent/10));f++)
           {
           cout<<"#";
           }
           f=0;
           for(;f<(7.7*(10-(percent/10)));f++)
           {
           cout<<"-";
           }
           cout<<"|"<<endl<<endl;
           f=0;
        
           cout << endl << "Please enter employee number >";
           cin >> employeenumber[c];
           do
           {
                cout << endl << "Please enter grade for employee number " << employeenumber[c] << " >";
		cin >> grade[c];
		invalidgrade='n';
		
		if (grade[c] <=0)
		{
			cout << endl<<"INVALID GRADE, please enter a valid grade"<<endl;
			invalidgrade='y';
		}
		if (grade[c] >3)
		{
			cout << endl<<"INVALID GRADE, please enter a valid grade"<<endl;
			invalidgrade='y';
		}
		}while(invalidgrade !='n');
		do
		{
		cout << endl << "Please enter hours worked this week by employee number " << employeenumber[c] << " >";
		cin >> totalhours[c];
		invalidhours='n';
				
		if (totalhours[c] >168)
		{
			cout << endl<<"INVALID HOURS, There are only 168 hours in a weeks so that is impossible!"<<endl;
			invalidhours='y';
		}
		else
		{if (totalhours[c]>60)
		{
			cout<<endl<<"My, that is a lot of hours, are you sure that it is correct?\nn to change, y to continue >"<<endl;
			cin >> q;cout<<endl;
		if (q!='n')
		{
			invalidhours='n';
		}
		else{
			invalidhours='y';}
		}}
				
		
		if (totalhours[c] < 0)
		{
			cout << endl << "INVALID HOURS, please enter a valid number of hours"<<endl;
			invalidhours='y';
		}
		}while(invalidhours != 'n');

		c++;


        system("cls");
        }
	
	c=0;

	for(;c<numberofemployees;)
	{
        if(totalhours[c]>38)
		{
			overtime[c]=totalhours[c]-38;
		}
		else
		{
			overtime[c]=0;
		}
	hours[c]=totalhours[c]-overtime[c];
	
	rate[c]=0;

/*	switch(grade[c])
	{
		case 1:rate[c]==10.5;
		case 2:rate[c]==15;
		case 3:rate[c]==20.5;
	}
*/


	if(grade[c]==1)
	{
		rate[c]=10.50;
	}
	else
	{
		if(grade[c]==2)
		{
			rate[c]=15.00;
		}
		else
		{
			if(grade[c]==3)
			{
				rate[c]=20.50;
			}
		}
	}

//	cout<<rate[c];cin>>null;

	grosspay[c]=(hours[c]*rate[c])+(overtime[c]*(rate[c]*1.5));
	super[c]=(grosspay[c]*.05);
	netpay[c]=(grosspay[c]-super[c]);
	
	if(netpay[c] < 600)
	{
		if(netpay[c] > 451)
		{
			taxrate[c]=.34;
		}
		else
		{
			if(netpay[c] >301)
			{
				taxrate[c]=.25;
			}
			else
			{
				if(netpay[c] > 201)
				{
					taxrate[c]=.15;
				}
				else
				{
					taxrate[c]=0;
				}
			}
		}
	}
	else
	{
		taxrate[c] = .46;
	}
	tax[c]=netpay[c]*taxrate[c];
	netpay[c]=netpay[c]-tax[c];

        system("cls");
                   percent=(float)(c+1)/numberofemployees*100;
           cout <<endl<<"|";
           f=0;
           for(;f<(7.7*(percent/10));f++)
           {
           cout<<"#";
           }
           f=0;
           for(;f<(7.7*(10-(percent/10)));f++)
           {
           cout<<"-";
           }
           cout<<"|"<<endl<<endl;
           f=0;


        cout <<"\n\n\n";
	cout << endl<<endl<<"Payslip for employee number: " << employeenumber[c]<<endl;
	cout << "---------------------------------------------------------------"<<endl;
	cout << endl << endl;
	cout << hours[c]<<" hours worked at $"<<rate[c]<<" per hour\t\t\t$"<<setprecision(5)<<hours[c]*rate[c]<<endl;
	cout << overtime[c]<<" hours of overtime at time and a half\t\t\t$"<<setprecision(5)<<overtime[c]*(rate[c]*1.5)<<endl;
	cout << "Gross pay\t\t\t\t\t\t$"<<setprecision(5)<<grosspay[c]<<endl;
	cout << "Superanuation\t\t\t\t\t\t$"<<setprecision(5)<<super[c]<<endl;
	cout << taxrate[c]*100<<"% Tax\t\t\t\t\t\t\t$"<<setprecision(5)<<tax[c]<<endl;
	cout << "---------------------------------------------------------------"<<endl<<endl;
	cout << "Net pay\t\t\t\t\t\t\t$"<<setprecision(5)<<netpay[c]<<endl;
	cout << "---------------------------------------------------------------"<<endl;
	c++;
//	if( c < numberofemployees)
//	{
	cout << "press enter to continue...";
		null = getchar();
//	}
//	else
//	{cout<<endl;}
	}
	return(0);
}
