Hi everyone. I'm a reta-I mean a beginner and 98% of my bugs are something really obvious... but I've checked this so much and I don't know what to do. This is my function to create an Employee object, called when the user wants to add a new employee to the system.

void EmployeeList::BuildEmployee (void)
   
                {
int skill, benefit;
string fstname, lstname;
long SSN;   
float hours, perCont;

                   
                    cout << "Enter employee first name" << endl;
                    getline (cin, fstname);
                    E2.setFirstName(fstname);

                    cin.ignore(10, '\n'); // somehow this line allows the next cout to print. I just found it in a sample program and it worked so I didn't question... *hides in shame*

                    cout << "Enter employee last name" << endl;
                   
                    getline (cin, lstname);

                    E2.setLastName(lstname);
               
                               
                    cout << endl << fstname << " " << lstname << endl;  // just to see if it ACTUALLY HAPPENED just within this function D:<
   
                    cout << "Enter social security number" << endl;
                    cin >> SSN;
                    E2.setSSN(SSN);
                   
                    cout << "Enter skill level" << endl;
                    cin >> skill;
                    E2.setSkill (skill);

                    cout << "Enter hours worked" << endl;
                    cin >> hours;
                    E2.setHours(hours);
           
                    cout << "Enter benefit code" << endl;
                    cin >> benefit;
                    E2.setBenefit(benefit);

                    if (skill == 4)
                        {
                            cout << "Enter retirement contribution percent" << endl;
                            cin >> perCont;
                            E2.setPercent(perCont);
                        }
       
                   
                }

So... say I want to hire Franziska Von Karma.

What prints is

Enter employee first name
--> Franziska
Enter employee last name
--> Von Karma

Von Karma
Enter social security number
... etc

So, the first name 'Franziska' is just ... completely NOT read. I know it's not the setters. And... the last name and the rest of it works fine. o_o

Ok the ugly cin.ignore is simply unnecessary. I have no idea why you might need it, it ignores the next 10 characters of input (say 10 random letters upto a return. Very strange. The std::endl should flush cout, so it should work. If you are using an old compiler you can add
cout.flush().

Other things that you might have wrong are that the call E2.setFirstName(fstname); might actually be to a method like this void setFirstName(std::string&); and then it changes the variable fstname.

I would also like to see some initialization of E2, and addition to the main list of employies. [along with some checking].

hope this helps but without some more code I can't help much more.

I am not sure what you mean by its not being read. I think it is being read thats why its printing it out. Just for making sure it is infact reading it, Here is a little name function I added. The name function would never output the names if they weren't being read.

#include<iostream>

using namespace std;

class EmployeeList
		 {
			public:
			EmployeeList(){}
			void BuildEmployee(void);
			string setFirstName(string);
			string setLastName(string);
			void setName(string,string);
		 };

string EmployeeList::setFirstName(string FName)
		{
			return FName;
		}


string EmployeeList::setLastName(string LName)
		{
			
			return LName;
		}



void EmployeeList::setName(string FName,string LName)
		{
			
			cout<< setFirstName(FName)<<" "<<setLastName(LName)<<endl;
		}


void EmployeeList::BuildEmployee (void)
		{

			int skill, benefit;
			string fstname, lstname;
			long SSN;
			float hours, perCont;
 

			cout << "Enter employee first name" << endl;
			getline (cin, fstname);
			setFirstName(fstname); 

				

			cout << "Enter employee last name" << endl;
			getline (cin, lstname);
			setLastName(lstname);

	
			setName(fstname,lstname);
			//cout << endl << fstname << " " << lstname << endl; 
			
 

		}

int main()
	 {
		EmployeeList var;
		var.BuildEmployee();
		return 0;
	 }

Sorry actually I didnt quite understand your question. But hope this helps.

Output:
[swj@localhost Problems]$ g++ test3.cpp
[swj@localhost Problems]$ ./a.out
Enter employee first name
Swaraj
Enter employee last name
Patil
Swaraj Patil

This article has been dead for over six months. Start a new discussion instead.