Hello all,

I am trying to make an employee program that takes in up to 100 max employees information then displays it back out nicely formatted, which I am not getting right and have been googling wtf I am doing wrong. Also I was wondering after inputting all the employee records how can I take and get an average of the companies age and income...if someone can please guide me in the right direction as I have been at this for 2 days really trying to learn and not sure what I am doing wrong. Thank you.

This is what i have so far:

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

class Employee {
string employeeName;
string employeeTitle;
int employeeAge;
long employeeSalary;
public:
void get_data(string, string, int, long);
void data_analysis();
void display_employee_list();
void display_stats();

};

void Employee::get_data(string ename, string etitle, int eage, long esalary)
{
employeeName = ename;
employeeTitle = etitle;
employeeAge = eage;
employeeSalary = esalary;
}
void Employee::display_employee_list()
{

cout<<employeeName << setw(20) << employeeTitle <<setw(19)<<employeeAge <<setw(21)<<employeeSalary<<endl;

}

int main ()
{

Employee employees[100];
int n = 0;
string ename, etitle;
int eage;
long esalary;
char again;
do {
cout <<setprecision(2)
<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint);
cout <<"Please enter employee name: ";
getline(cin, ename);
cout << endl;
cout <<"Please enter employee title: ";
getline(cin, etitle);
cout << endl;
cout <<"Please enter employee age: ";
cin >> eage;
cout << endl;
cout <<"Please enter employee salary: ";
cin >> esalary;
cout << endl;
employees[n++].get_data(ename, etitle,eage,esalary);
cout <<"Next Employee? Type n or N to stop the data entry. ";
cin >> again;
cin.ignore();
cout <<endl;
} while(again =='y');
cout << "\t\tEmployee Statistical Report:" << endl;
cout <<endl;
cout <<"Employee Name" <<setw(20)<<"Employee Title" <<setw(18)<< "Age" <<setw(20) <<"Salary" <<endl;
for (int i=0; i<n; i++)
{
employees[i].display_employee_list();

}
cout <<endl;
system("PAUSE");

return 0;
}

Compare

cout << employeeName << setw(20) << employeeTitle << setw(19) << employeeAge << setw(21) << employeeSalary << endl;

and

cout << "Employee Name" << setw(20) << "Employee Title" << setw(18) << "Age" << setw(20) << "Salary" << endl;

I see two things to fix:

  1. You're not setting the same widths for the title row and the data rows.
  2. You're not setting a width for the employee name field.
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.