#include<iostream>//standard header file
#include <unistd.h>//for sleep funtion
#include <string>//for string purposes ( strcmp )
#include <cctype>// for tolower or toupper ( type of input )

using namespace std;

const double murah = 0.5;
const double singgit = 1.0;
const double weekend = 0.2;

char table_day_choice_menu( );
int time_parked();
int duration_parked( );
void calculation_fee( char , int , int );
void resit(char , int , int , int , int , double );

int main(void)
{
	char day;
	int time;
	int duration;
	float fee;
	char termination;
	
	while(1)
	{
		day=table_day_choice_menu();
		time=time_parked();
		duration=duration_parked();
		calculation_fee(day, time, duration);
		cout<<"\nDo you wish to continue? (Y/N)";
		cin>>termination;
		if(termination == 'n' || termination == 'N')
		{
			break;
		}
	}
}
void calculation_fee(char day,int time,int duration)
{
	char Outday, Inday;
	int HHT, MMT, Outtime;
	double pay;
	int Intime, Length_stay;
	
	Length_stay = duration;
	
	Inday = day;
	Outday = day;
	Intime = time;
	
	HHT = time/100;
	MMT = time-(HHT*100);
	
	pay=0;
	
	while(1)
	{
		MMT++;
		duration--;
		if ( Outday == 'a' || Outday == 'b' || Outday == 'c' || Outday == 'd' || Outday == 'e')
		{
			if( HHT < 8 || HHT >= 18 && HHT <24)
			{
				pay+=murah;
			}
			else if ( HHT >=8 && HHT <18)
			{
				pay +=singgit;
			}
			if(HHT==24)
			{
				HHT=0;
				Outday++;
			}
			if( MMT ==60)
			{
				HHT+=1;
				MMT =0;
			}
		}
		if ( Outday == 'f' )
		{
			pay+=weekend;
			if(HHT==24)
			{
				HHT=0;
				Outday++;
			}
			if( MMT ==60)
			{
				HHT+=1;
				MMT =0;
			}
		}
		if(duration<=0)
		{
			break;
		}
		if (Outday == 'g')
		{
			pay+=weekend;
			if(HHT==24)
			{
				HHT=0;
				Outday='a';
			}
			if( MMT ==60)
			{
				HHT+=1;
				MMT =0;
			}
		}
		if(duration<=0)
		{
			break;
		}
	}
	
	Outtime = ( HHT*100) + MMT;
	
	resit(Inday, Intime, Length_stay, Outday, Outtime, pay);
}
void resit(char dayIn, int time, int duration, int Outday, int Outtime, double fee)
{
	cout<<"\n  _____________________________________________\n";
	cout<<"  `````````````````````````````````````````````\n";
	cout<<"  Vehicle parked on 	        :>  ";
	if( dayIn == 'a')
	{
		cout<<"Monday"<<endl;
	}
	if( dayIn == 'b')
	{
		cout<<"Tuesday"<<endl;
	}
	if( dayIn == 'c')
	{
		cout<<"Wednesday"<<endl;
	}
	if( dayIn == 'd')
	{
		cout<<"Thursday"<<endl;
	}
	if( dayIn == 'e')
	{
		cout<<"Friday"<<endl;
	}
	if( dayIn == 'f')
	{
		cout<<"Saturday"<<endl;
	}
	if( dayIn == 'g')
	{
		cout<<"Sunday"<<endl;
	}
	cout<<"  Vehicle started parking at    :>  "<<time<<" HOURS"<<endl;
	cout<<"  Vehicle parked for 		:>  "<<duration<<" MINS"<<endl;
	cout<<"  Vehicle exited parking on	:>  ";
	if( Outday == 'a')
	{
		cout<<"Monday"<<endl;
	}
	if( Outday == 'b')
	{
		cout<<"Tuesday"<<endl;
	}
	if( Outday == 'c')
	{
		cout<<"Wednesday"<<endl;
	}
	if( Outday == 'd')
	{
		cout<<"Thursday"<<endl;
	}
	if( Outday == 'e')
	{
		cout<<"Friday"<<endl;
	}
	if( Outday == 'f')
	{
		cout<<"Saturday"<<endl;
	}
	if( Outday == 'g')
	{
		cout<<"Sunday"<<endl;
	}
	
	cout<<"                          at	:>  "<<Outtime<<" HOURS"<<endl;
	printf("  Ammount parking fee           :>  RM%.2f\n", fee);
	cout<<endl;
	cout<<"   ~~~~~~~ Thanks for parking with us ~~~~~~~~\n";
	cout<<"  _____________________________________________\n";
	cout<<"  ---------------------------------------------\n";
}
int duration_parked()
{
	int mins;
	cout<<"  Enter the duration the car parked for (in mins)\n";
	cout<<"   >>";
	cin>>mins;
	return mins;
}
int time_parked()
{
	int hours;
	cout<<"  Enter the time car stared to park (HHMM)\n";
	cout<<"   >>";
	cin>>hours;
	return hours;
	
}
char table_day_choice_menu()
{
	char hari;
	char x[3];
	char a[3]="mo";
	char b[3]="tu";
	char c[3]="we";
	char d[3]="th";
	char e[3]="fi";
	char f[3]="sa";
	char g[3]="su";
	int i;
	
	START:
	
	system("cls");
	cout<<"\n";
	cout<<"  _____________________________________________\n";
	cout<<" |*********************************************|\n";
	cout<<" |*|        AUTOPAY MACHINE CALCULATOR       |*|\n";
	cout<<" |*|        --------------------------       |*|\n";
	cout<<" |*********************************************|\n";
	cout<<" |*|          DAY            |=|    code     |*|\n";
	cout<<" |*|        Monday           |=|     Mo      |*|\n";
	cout<<" |*|       Tuesday           |=|     Tu      |*|\n";
	cout<<" |*|      Wednesday          |=|     We      |*|\n";
	cout<<" |*|      Thursday           |=|     Th      |*|\n";
	cout<<" |*|       Friday            |=|     Fi      |*|\n";
	cout<<" |*|      Saturday           |=|     Sa      |*|\n";
	cout<<" |*|       Sunday            |=|     Su      |*|\n";
	cout<<" |*********************************************|\n";
	cout<<"  ---------------------------------------------\n";
	cout<<"  Enter the day (code) car was parked \n";
	cout<<"   >>";
	cin>>x;
	
	for(i=0; i<3; i++)
	{
		x[i]=tolower(x[i]);
	}
	if ( !strcmp(x, a))
	{
		hari='a';
	}
	else if ( !strcmp(x, b))
	{
		hari='b';
	}
	else if ( !strcmp(x, c))
	{
		hari='c';
	}
	else if ( !strcmp(x, d))
	{
		hari='d';
	}
	else if ( !strcmp(x, e))
	{
		hari='e';
	}
	else if ( !strcmp(x, f))
	{
		hari='f';
	}
	else if ( !strcmp(x, g))
	{
		hari='g';
	}
	else
	{
		cout<<"  Invalid code input. \n Please re-enter.";
		sleep(1);
		goto START;
	}
	return hari;
}
