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;
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)
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;
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++)

cout <<endl;

return 0;

Edited by Dani: Code formatting

4 Years
Discussion Span
Last Post by gusano79


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


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.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.