I have this main as a part of a bigger program, but every time I run the program, I only get the output of the loop once and then the program exits with a huge int as the return. How do I figure out what the problem is/ where is the problem in my code?
I've tried playing around with the limits on i to no avail.
#include <iostream>
#include <typeinfo>
#include "Employee.h"
#include "Staff.h"
#include "Education.h"
#include "Faculty.h"
#include "Parttime.h"
using namespace std;
int main() {
Staff s1("Allen", "Paita", "123", "M", "2/23/59", 50.00);
Staff s2("Zapata", "Steven", "456", "F", "7/12/64", 35.00);
Staff s3("Rios", "Enrique", "789", "M", "6/2/70", 40.00);
Education e1("PHD", "Engineering", 3);
Education e2("PHD", "English", 1);
Education e3("MS", "Physical Education", 0);
Faculty f1("Johnson", "Anne", "243", "F", "4/27/62", "FU", e1);
Faculty f2("Bouris", "William", "791", "M", "3/14/75", "AO", e2);
Faculty f3("Andrade", "Christopher", "623", "M", "5/22/80", "AS", e3);
Parttime p1("Guzman", "Augusto", "455", "F", "8/10/77", 35.00, 30);
Parttime p2("Depirro", "Martin", "678", "F", "9/15/87", 30.00, 15);
Parttime p3("Aldaco", "Marque", "678", "F", "11/24/88", 20.00, 35);
Employee *eArray[] = {&p2, &s2, &s3, &s1, &f1, &f3, &p1, &f2, &p3};
double totalPartTime = 0;
double trueTotal = 0;
for (int i = 0; i < sizeof(eArray) / sizeof(eArray[0]); i++) {
if (typeid(*eArray[i]) == typeid(Staff)) {
cout << "Staff: \n";
Staff * s = dynamic_cast<Staff*>(eArray[i]);
s->putData();
}
else if (typeid(*eArray[i]) == typeid(Faculty)) {
cout << "Faculty: \n";
Faculty * f = dynamic_cast<Faculty*>(eArray[i]);
f->putData();
}
else if (typeid(*eArray[i]) == typeid(Parttime)) {
cout << "Parttime: \n";
Parttime * p = dynamic_cast<Parttime*>(eArray[i]);
p->putData();
totalPartTime += p->monthlyEarnings();
}
else {
cout << "Employee: \n";
eArray[i]->putData();
}
trueTotal += eArray[i]->monthlyEarnings();
cout << endl;
}
cout << "Total Monthly Salary for all Part-Time Staff: " << totalPartTime << endl;
cout << "Total Monthly Salary for all Employees: " << trueTotal << endl;
return 0;
}
The output should be a list of outputs for each employee, but I'm only getting one output and this message:
Process exited after 0.6195 seconds with return value 3221226356