I am learning C ++. I have a problem formatting the output of my program. I would like to print columns that match perfectly, but so far I cannot do this, here is my code:
int main()
{
employee employees[5];
employees[0].setEmployee("Stone", 35.75, 053);
employees[1].setEmployee("Rubble", 12, 163);
employees[2].setEmployee("Flintstone", 15.75, 97);
employees[3].setEmployee("Pebble", 10.25, 104);
employees[4].setEmployee("Rockwall", 22.75, 15);
printEmployees(employees, 5);
return 0;
}
void printEmployees(employee employees[], int number)
{
int i;
for (i=0; i<number; i++) {
employees[i].printEmployee();
}
cout << "\n";
}
class employee I have a print employee method:
void printEmployee() const
{
cout << fixed;
cout << surname << setw(10) << empNumber << "\t" << setw(4) << hourlyRate << "\n";
}
The problem is that when printing the line "flinstones" the emp number and speed do not line up. something like that:
Stone 43 35.750000
Rubble 163 12.000000
Flintstone 97 15.750000
Pebble 104 10.250000
Rockwall 15 22.750000
Can someone help me? (I tried to add tabs .. but that didn't help)
source
share