Ok, I'm doing my course work and I've managed to get it so that the menu will only show values if they've been entered, for example:
if number_of_employees is 0
then
display add employee
otherwise
display add employee
display view employee
endif
The problem that I'm having is that it's in a switch statement and if someone wants to, somehow view the employees details and there isn't an employee, it's going to be rather difficult. So I thought about using an Exception but it doesn't seem to be working. Here's my code:
case '3': system("cls");
system("TITLE View Employees");
int choice;
system("cls");
try
{
cout << "Employee ID: ";
cin >> choice;
Sleep(400);
// display the employees details
cout << "Employees Name: " << employees[choice + 1].getFirstName() << " " << employees[choice].getLastName() << endl;
cout << "Employees Adress: " << employees[choice + 1].getAddress() << endl;
cout << "Employee Hours: " << employees[choice + 1].getHours() << endl;
cout << "Employee Gross Wage: " << employees[choice + 1].calculateGrossPay() << endl;
cout << "Employee Net Wage: " << employees[choice + 1].calculateTax() << endl << endl << endl;
system("PAUSE");
}
catch(char error[255])
{
error = "Error: You cannot view employees since there are none availible";
if(number_of_employees == 0)
cout << error;
}
break;
Any suggestions?