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?

>>I thought about using an Exception

There is no need to use exception here because it will only complicate your
code. Why not just display nothing? Or display a message saying
no employees to show. Do something like this :

if(choice == VIEW_EMPLOYEES){
  if(employees.empty()) {
     displayErrorMessage()
   }
   else displayEmployees();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.