Attempting to finish a project for my course

I'm trying to build a program that prompts the user to enter an employee name and the number of hours that employee has worked, then outputs a small dossier that includes the employees name, hours worked, wage in $/hour, number of overtime hours worked, and total earnings. The earnings are calculated as the wagexhours for the first 40 hours, plus wagex1.5xhours for all overtime hours. All of this must be in one .cpp file, and it must be a Win32 application. I cannot understand the error messages I am receiving. Any tips would be greatly appreciated!


#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

void employeeInput( string firstName, string lastName );
double calculatePay( double hours, double wage );

string firstName;
string lastName;
double hours;
double wage = 10.0;
void print();

void employeeInput()
{
cout << "Enter employee name ( first last ): ";
cin >> firstName >> lastName;
cout << "Enter number of hours employee has worked this week: ";
cin >> hours;
cout << "\n\n\n";
}
double calculatePay()
{
return ( ( hours <= 40 ) ? hours * wage : ( 40 * wage ) + ( ( hours - 40 ) * ( wage * 1.5 ) ) );
}
void print()
{
cout << "Employee: " << lastName << ", " << firstName
<< "\nTotal hours worked: " << hours
<< "\nOvertime hours: " << ( hours - 40 )
<< "\nWage in $/hour: " << wage
<< "\n\nTotal pay: $" << calculatePay( hours, wage ) << endl;
}
int main()
{
employeeInput( firstName, lastName );
print();
}


1>------ Build started: Project: OpSeven, Configuration: Debug Win32 ------
1>Compiling...
1>Employee.cpp
1>Linking...
1>Employee.obj : error LNK2019: unresolved external symbol "double __cdecl calculatePay(double,double)" (?calculatePay@@YANNN@Z) referenced in function "void __cdecl print(void)" (?print@@YAXXZ)
1>Employee.obj : error LNK2019: unresolved external symbol "void __cdecl employeeInput(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?employeeInput@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) referenced in function _main
1>Z:\Visual Studio 2008\Projects\OpSeven\Debug\OpSeven.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://z:\Visual Studio 2008\Projects\OpSeven\OpSeven\Debug\BuildLog.htm"
1>OpSeven - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
This:

void employeeInput( string firstName, string lastName );

Doesn't match this:

1
2
3
4
5
6
7
8
void employeeInput()
{
cout << "Enter employee name ( first last ): ";
cin >> firstName >> lastName;
cout << "Enter number of hours employee has worked this week: ";
cin >> hours;
cout << "\n\n\n";
}


Your function declaration has arguments listed, but you aren't listing any arguments for your definition. The same goes for your calculatePay function.
Last edited on

Your function declaration has arguments listed, but you aren't listing any arguments for your definition.

:)
Last edited on
Oops. Fixed now. Thanks, moorecm.
That solves the actual error messages, but every time I try to run this program, it refuses to display the employee name.


#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

void employeeInput( string firstName, string lastName );
double calculatePay( double hours, double wage );

string firstName;
string lastName;
double hours;
double wage = 10.0;
void print();

void employeeInput( string firstName, string lastName )
{
cout << "Enter employee name ( first last ): ";
cin >> firstName >> lastName;
cout << "Enter number of hours employee has worked this week: ";
cin >> hours;
cout << "\n\n\n";
}
double calculatePay( double hours, double wage )
{
return ( ( hours <= 40 ) ? hours * wage : ( 40 * wage ) + ( ( hours - 40 ) * ( wage * 1.5 ) ) );
}
void print()
{
cout << "Employee: " << lastName << ", " << firstName
<< "\nTotal hours worked: " << hours
<< "\nOvertime hours: " << ( hours - 40 )
<< "\nWage in $/hour: " << wage
<< "\nTotal pay: $" << calculatePay( hours, wage ) << endl;
}
int main()
{
employeeInput( firstName, lastName );
print();
}


Enter employee name ( first last ): John Smith
Enter number of hours employee has worked this week: 50



Employee: ,
Total hours worked: 50
Overtime hours: 10
Wage in $/hour: 10
Total pay: $550
Press any key to continue . . .
string firstName and lastName need to be passed by reference.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

void employeeInput( string firstName, string lastName );
double calculatePay( double hours, double wage );

string firstName;
string lastName;
double hours;
double wage = 10.0;
void print();

void employeeInput( string &firstName, string &lastName )
{
	cout << "Enter employee name ( first last ): ";
	cin >> &firstName >> &lastName;
	cout << "Enter number of hours employee has worked this week: ";
	cin >> hours;
	cout << "\n\n\n";
}
double calculatePay( double hours, double wage )
{
	return ( ( hours <= 40 ) ? hours * wage : ( 40 * wage ) + ( ( hours - 40 ) * ( wage * 1.5 ) ) );
}
void print()
{
	cout << "Employee: " << lastName << ", " << firstName
		<< "\nTotal hours worked: " << hours
		<< "\nOvertime hours: " << ( hours - 40 )
		<< "\nWage in $/hour: " << wage
		<< "\nTotal pay: $" << calculatePay( hours, wage ) << endl;
}
int main()
{
	employeeInput( firstName, lastName );
	print();
}

1>------ Build started: Project: OpSeven, Configuration: Debug Win32 ------
1>Compiling...
1>Employee.cpp
1>z:\visual studio 2008\projects\opseven\opseven\employee.cpp(18) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string *' (or there is no acceptable conversion)
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(1144): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(1146): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(1148): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char *)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(1150): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\string(592): or       'std::basic_istream<_Elem,_Traits> &std::operator >><char,std::char_traits<char>,std::allocator<_Ty>>(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Ax> &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>,
1>            _Ty=char,
1>            _Ax=std::allocator<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(155): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits> &(__cdecl *)(std::basic_istream<_Elem,_Traits> &))'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(161): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(168): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(175): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::_Bool &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(194): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(short &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(228): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned short &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(247): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(int &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(273): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned int &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(291): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(309): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__w64 unsigned long &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(329): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__int64 &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(348): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned __int64 &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(367): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(float &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(386): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(double &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(404): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long double &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(422): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(void *&)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(441): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_streambuf<_Elem,_Traits> *)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        while trying to match the argument list '(std::istream, std::string *)'
1>z:\visual studio 2008\projects\opseven\opseven\employee.cpp(37) : error C2668: 'employeeInput' : ambiguous call to overloaded function
1>        z:\visual studio 2008\projects\opseven\opseven\employee.cpp(15): could be 'void employeeInput(std::string &,std::string &)'
1>        z:\visual studio 2008\projects\opseven\opseven\employee.cpp(6): or       'void employeeInput(std::string,std::string)'
1>        while trying to match the argument list '(std::string, std::string)'
1>Build log was saved at "file://z:\Visual Studio 2008\Projects\OpSeven\OpSeven\Debug\BuildLog.htm"
1>OpSeven - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


This is the error message I received from the above code. I couldn't fit them both in one post.
You need to add the ampersand below for both firstName and lastName.

void employeeInput( string firstName, string lastName );

And you need to remove the ampersands from below. They're not needed.

cin >> &firstName >> &lastName;
Thank you so much for the help!
Topic archived. No new replies allowed.