Im writing a program that simulates a clock in device such as those normally used in a workplace. I want my program to be able to clock-in multiple employees instead of just one. Every time I have my program clock someone in, it pretty much overwrites whoever was clocked in before. What function should I use to allow for several clock-ins?
void clockIn::mainMenu()
{
std::cout << "Welcome to LePelch Corporations\n";
std::cout << "What can I do for you today?\n\n";
std::cout << "1) Clock in\n" << "2) Clock out\n" << "3) Create Employee ID\n" << "4) Nothing, exit." << endl;
std::cin >> mainMENU;
while(mainMENU!=4)
{ if(mainMENU==1)
{ std::cout << "\nWelcome to the Clock-In menu, please enter your employee ID, or enter '0' to exit to menu.\n" << endl;
std::cin >> clockIn;
while (clockIn!=0)
{
if (empID[e]==clockIn)
{
std::cout << "You are already clocked in!" << endl;
break;
}
for(i=0; i<3; i++)
{
if(empID[i]==clockIn)
{
e=i;
flag=1;
i=ii;
break;
}
}
if(flag==1)
{
time (&start);
std::cout << clkNAM[e] << endl;
std::cout << "Clock-in accepted.\n" << endl;
break;
}
else std::cout << "\nERROR! Please try again\n" << endl;
break;
}
}
else if(mainMENU==2)
{
std::cout << "\nWelcome to the Clock-Out menu, please enter your employee ID, or enter '0' to exit to menu.\n" << endl;
std::cin >> clockOut;
while (clockOut!=0)
{
for(i=0; i<3; i++)
{
if(empID[i]==clockOut and empID[i]==clockIn)
{
i=e;
flagTwo=1;
i=ii;
break;
}
}
if(flagTwo==1 and flag==1)
{
time (&end);
std::cout << clkNAM[e] << endl;
std::cout << "Clock-out accepted.\n" << endl;
double dif = difftime (end,start);
double minutes = dif/60;
double hours = minutes/60;
std::cout << "You have worked " << setprecision(3) << hours << " hours today. Have a nice day!\n" << endl;
break;
}
else if(flagTwo==1 and flag!=1)
{
std::cout << "\nERROR! You have not clocked in yet. Please clock-in before clocking-out. Thank you.\n" << endl;
}
else std::cout << "\nERROR! Please try again\n" << endl;
break;
}
}
else if(mainMENU==3)
{
std::cout << "Welcome. Punch in number to create new employee ID" << endl;
std::cin >> newNUM;
string line;
fstream empNUM,clokNAM;
empNUM.open("/Users/lepelch23alex/Dropbox/School/Computer Programming/New Clock in Device/Employee ID's.txt");
I suggest to use std::map<int, ClockTime> inside your clock class.
ClockTime is defined as: using ClockTime = std::pair<int, int> (or pair of strings, or time_point, or whichever you use to represent time)