I am creating a program that takes the user's information and displays it back on the screen. I have been successful in getting the majority of the program to work great. However, I am stuck on why the information isn't being processed by the class correctly. It seems to simply give me variable information that seems to be set to blank. The values output "-858993460". I am not very familiar with working with constructors, and I believe my problem is how the information is being sent to the class. If anyone can give me a good place to start, I would greatly appreciate your help.
#include <iostream>
#include <iomanip>
#include <string>
#include "Employee.h"
#include "ProductionWorker.h"
usingnamespace std;
using std::string;
int main()
{
string name;
int number = 0;
int date = 0;
int empShift = 0;
double empPayRate = 0.0;
//Create a ProductionWorker object
ProductionWorker stats;
//Define info object and initalize it with values entered
Employee info(name, number, date);
//Get the employee's name
cout << "Enter the employee's name: ";
getline(cin, name);
//Get the employee's number
cout << "Enter the employee's number: ";
cin >> number;
//Get the date the employee was hired
cout << "Enter the date the employee was hired: ";
cin >> date;
//Get the employee's shift
cout << "Enter the employee's shift where day shift = 1 and night shift = 2: ";
cin >> empShift;
//Get the employee's pay rate
cout << "Enter the employee's pay rate in decimal format (0.00): ";
cin >> empPayRate;
//Store the employee's shift and pay rate into the stats object
stats.setShift(empShift);
stats.setPayRate(empPayRate);
//Display the results
cout << "\nThe employee's name is " << info.getEmployeeName() << endl;
cout << "The employee's number is " << info.getEmployeeNumber() << endl;
cout << "This employee was hired on " << info.getHireDate() << endl;
cout << setprecision(3);
cout << "This worker has the " << stats.getNameShift() << " shift and" << endl;
cout << "makes $" << empPayRate << " per hour" << endl;
cin.get();
cin.get();
return 0;
}
Well. Right off the bat I can see what could be giving you some problems. I didn't run the code but you create Employee info(name, number, date). name hasn't been initialized to anything. number and date are both initialized to 0. So when you create the employee object. you are sending in parameters that have been initialized to 0 or nothing. Try creating the employee object after you have taken in the input from the user. I would start there.
Thank you for your quick response. I meant to respond sooner, but work has kept me very busy the past 2 days.
I was able to find my problem thanks to you. I had to pass the information like you mentioned and also set up proper mutator functions in my employee.h class. For some reason my hiredate still doesn't want to work, but i can live with that.