I am trying to write a program that asks for a first name, last name, and salary. I have got it to ask for first name and last name, but I cannot seem to introduce salary as an integer variable in the class definition. I have tried it a bunch of different ways and I keep getting errors.
#include "stdafx.h"
#include <iostream> // allows basic input\output
#include <string> // allows string class
using namespace std; // sets namespace to std
// Employee class defintion
class Employee
{
public: // sets function to public
void displayFirstName( string fname ) // function header
{
cout << endl; // starts new line
cout <<"Employee's first name is: " << fname << endl; // displays employee's first name
cout << endl; // starts a new line
} //end function displayFirstName
public: // sets function to public
void displayLastName( string lname ) // function header
{
cout << endl; // starts new line
cout << "Employee's last name is: " << lname << endl; // displays employee's last name
cout << endl; // starts a new line
} // end function display LastName
}; // end class Employee
int _tmain(int argc, _TCHAR* argv[])
{
string firstName; // characters used to store FirstName
Employee myEmployee; // create an object named myEmployee
cout << "Enter employee's first name: " << endl; // asks user for First Name
cout << endl; // starts new line
getline( cin, firstName ); // reads a line of text
myEmployee.displayFirstName( firstName ); // calls function display FirstName
string lastName; // characters to store LastName
cout << "Enter employee's last name: " << endl; // asks user for Last Name
cout << endl; // starts new line
getline(cin, lastName ); // reads a line of text
myEmployee.displayLastName( lastName ); // calls function display LastName
return 0;
} // end main
This is what I have so far. I have tried introductin salary at the very beginning under the includes, at the beginning of the class definition and even at the beginning of the main function. I do know that it has to be introduced in the class definition
#include "stdafx.h"
#include <iostream> // allows basic input\output
#include <string> // allows string class
usingnamespace std; // sets namespace to std
// Employee class defintion
class Employee
{
public: // sets function to public
void displayFirstName( string fname ) // function header
{
cout << endl; // starts new line
cout <<"Employee's first name is: " << fname << endl; // displays employee's first name
cout << endl; // starts a new line
} //end function displayFirstName
public: // sets function to public
void displayLastName( string lname ) // function header
{
cout << endl; // starts new line
cout << "Employee's last name is: " << lname << endl; // displays employee's last name
cout << endl; // starts a new line
} // end function display LastName
}; // end class Employee
int _tmain(int argc, _TCHAR* argv[])
{
string firstName; // characters used to store FirstName
Employee myEmployee; // create an object named myEmployee
cout << "Enter employee's first name: " << endl; // asks user for First Name
cout << endl; // starts new line
getline( cin, firstName ); // reads a line of text
myEmployee.displayFirstName( firstName ); // calls function display FirstName
string lastName; // characters to store LastName
cout << "Enter employee's last name: " << endl; // asks user for Last Name
cout << endl; // starts new line
getline(cin, lastName ); // reads a line of text
myEmployee.displayLastName( lastName ); // calls function display LastName
return 0;
} // end main