Currently working on a homework assignment, and I've read my book. I'm supposed to create a class that has an array in it, for hours worked by each person. All fine and dandy, except that when I leave a function and return to main, anything that was changed in that class is now back to what it was before, or atleast, that's how I see it. But this isn't even my problem right now, I'm trying to create an array in my gethours function, then pass it's pointer of said array back to my main function, then pass the pointer to display function. However, it's just not working. Like, at all.
CODE
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class payroll {
public:
int employeeHours[5];
string employeeName[5] = { "David", "Steve", "Vanessa", "Groot", "Poyo" };
double hourlyPay = 12.55;
};
int getHours() {
payroll payroll;
int hours[5] = {0,0,0,0,0};
for (int i = 0; i != 5; i++) {
cout << "How many hours did " << payroll.employeeName[i] << " work? ";
cin >> hours[i];
cout << endl;
}
return *hours;
}
int *display(int *hours) {
payroll payroll;
for (int i = 0; i != 5; i++) {
cout << payroll.employeeName[i] << " has " << *(hours + i) << " hours. " << i << endl;
}
return 0;
}
int main() {
payroll payroll;
int *hours;
hours = new int[5];
*hours = getHours();
for (int i = 0; i != 5; i++) { //Testing, ignore
cout << payroll.employeeName[i] << " has " << *(hours + i) << " hours. " << i << endl;
}
display(hours);
system("Pause");
}
Now you may look at this and wonder, "Why if the assignment asks for the class to hold the array, do you have another array?" Well for me, I tried using the class array, which worked fine and dandy all inside the same function, but as said before, once I leave that function, it gets reset. So, I'm using a separate array as testing until I can figure out how I'm actually storing the variables.