Hello all,

I have put together an inventory program and having problems getting it to compile and run. I am at my wits end, with it. I'm not sure what it is that I'm missing. Any help would be greatly appreciated. Thanks in advance.

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
#define MAX_EMPLOYEES 3 // we only want 3 in this exercise
//
//CLASS DECLARATION SECTION
//
class EmployeeClass 
{
public:
// constructor/destructor
EmployeeClass();
~EmployeeClass();
// employee functions
int AddEmployee();
int DeleteEmployee();

// output functions
int PrintTimesheets();
int PrintSummary();
// member variables
int m_TotalEmployees;
 
private:
// member variable 
struct _Employee
{
char Name[255];
float HoursWorked;
float HourlyWage;
float BasePay;
float OvertimeHours;
float OvertimePay;
float TotalPay;
} Employee[MAX_EMPLOYEES];
 
struct _Summary
{
float TotalEmployeeSalaries;
float TotalEmployeeHours;
float TotalOvertimeHours;
} Summary;
// calculation functions
int CalcPay(int);
 
 
};
 
// constructor / destructor functions
EmployeeClass::EmployeeClass(void)
{
m_TotalEmployees = 0;
}
EmployeeClass::~EmployeeClass(void)
{

}
 
 
int EmployeeClass::AddEmployee()
{

cout << "Enter the employee name = ";
cin >> Employee[m_TotalEmployees].Name;
cout << "Enter hours worked = ";
cin >> Employee[m_TotalEmployees].HoursWorked;
cout << "Enter his or her hourly rate = ";
cin >> Employee[m_TotalEmployees].HourlyWage;
cout << endl;

CalcPay(m_TotalEmployees);
m_TotalEmployees++;
return 0;
}
 
int EmployeeClass::DeleteEmployee()
{
return 0;
}
int EmployeeClass::CalcPay(int i)
{

if ( Employee[i].HoursWorked == 0 || Employee[i].HoursWorked < 0)
{
Employee[i].BasePay = 0;
Employee[i].OvertimeHours =0;
Employee[i].OvertimePay = 0;
Employee[i].TotalPay = 0;
Summary.TotalEmployeeHours = Summary.TotalEmployeeHours + Employee[i].HoursWorked;
}
if ( Employee[i].HoursWorked <= 40 && Employee[i].HoursWorked > 0)
{
Employee[i].BasePay = Employee[i].HoursWorked * Employee[i].HourlyWage;
Employee[i].OvertimeHours =0;
Employee[i].OvertimePay = 0;
Employee[i].TotalPay = Employee[i].BasePay;
Summary.TotalEmployeeHours = Summary.TotalEmployeeHours + Employee[i].HoursWorked;
}
 
if ( Employee[i].HoursWorked > 40)
{

Employee[i].BasePay = 40 * Employee[i].HourlyWage;
Employee[i].OvertimeHours = Employee[i].HoursWorked - 40;
Employee[i].OvertimePay = Employee[i].OvertimeHours * (Employee[i].HourlyWage * 1.5);
Employee[i].TotalPay = Employee[i].BasePay + Employee[i].OvertimePay;
Summary.TotalEmployeeHours = Summary.TotalEmployeeHours + (Employee[i].HoursWorked - 40);
}
Summary.TotalEmployeeSalaries = Summary.TotalEmployeeSalaries + Employee[i].TotalPay;


return 0;
}
 
int EmployeeClass::PrintTimesheets()
{
 
 
for (int i = 0; i < MAX_EMPLOYEES; i++)
{
cout << "Employee Name ............. = " << Employee[i].Name << endl;
cout << "Base Pay .................. = " << Employee[i].BasePay << endl;
cout << "Hours in Overtime ......... = " ;

if (Employee[i].HoursWorked < 40)
cout << 0 << endl;
else
cout << (Employee[i].HoursWorked - 40) << endl;
cout << "Overtime Pay Amount........ = " << Employee[i].OvertimePay << endl;
cout << "Total Pay ................. = " << Employee[i].TotalPay << endl;
cout << endl;
}
 
return 0;
}
int EmployeeClass::PrintSummary()
{

cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%% EMPLOYEE SUMMARY DATA%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%% Total Employee Salaries ..... = " << Summary.TotalEmployeeSalaries << endl;
cout << "%%%% Total Employee Hours ........ = " << Summary.TotalEmployeeHours << endl;
cout << "%%%% Total Overtime Hours......... = " << Summary.TotalOvertimeHours << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << endl;
return 0;
}
 
int main()
{
system("cls"); 
cout << "\nWelcome to the Employee Pay Center\n\n" ;
// global
EmployeeClass ec;
// add employees
while (ec.m_TotalEmployees < MAX_EMPLOYEES)
{
ec.AddEmployee();
}
// print employee results
ec.PrintTimesheets();

// print summary 
ec.PrintSummary();
return 0;
}

... having problems getting it to compile and run.

It is always best if you give the exact compilation error message, so we don't have to guess what the problem might be. And, if you read the error message carefully, thinking about how a compiler author has to be generic, you may find that it is actually quite helpful in explaining what the compiler thinks went wrong. Of course after the first error, the compiler is confused anyway, so ignore the rest.

Just a word to the wise: Indenting your code is very helpful in keeping track of the levels of nesting. Your code apparently lacks that nice feature.

A little information put huge functions in a header then #include that header usually with #include "myheader.h" or "myheader.hpp" that way if the error is in one of the functions the compiler will be a tiny bit more information in spitting errors out.
also i do hope your not using the outdated devshed c++ compiler. :p no offense but there are better compilers out there namely g++(mingw on windows, or cygwin).

Also as griswolf suggested posting your compiler error helps us out in helping you out.

but being the care free nix user i am ill try to compile what you have and post some helpful hints i won't post actual code as this looks very close to a homework assignment from a uni or community college.
posting what you have tried to do to fix it is always great help :P

basically you have a bunch and i mean a bunch of stray escape characters in your code
\200
\343
a bunch of times over and over now im not an expert in text encoding but id say your using a weird format or your os's newline/carriage return is one of those to escapes? it won't show up in a regular text editor i can't even seem to see it in nano or vi or even emacs.

also

main.cpp:154:13: error: ‘system’ was not declared in this scope

so search for the appropriate header for system on google and fix your text encoding.

you can see it in your code i just now saw those ascii boxes ie ([])just retype your code in a plain text editor like notepad/gedit/ don't use microsoft office or open office or word to code in

Thanks for the advice. Here are my errors.

1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(26): error C3872: '0x3000': this character is not allowed in an identifier
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(27): error C2143: syntax error : missing ';' before 'private'
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(27): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(39): error C3872: '0x3000': this character is not allowed in an identifier
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(41): error C2143: syntax error : missing ';' before '<class-head>'
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(41): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(48): error C3872: '0x3000': this character is not allowed in an identifier
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(49): error C3872: '0x3000': this character is not allowed in an identifier
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(50): error C2146: syntax error : missing ';' before identifier ' '
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(50): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(50): error C2143: syntax error : missing ';' before '}'
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(50): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(51): error C3872: '0x3000': this character is not allowed in an identifier
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(53): error C2143: syntax error : missing ';' before 'EmployeeClass::{ctor}'
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(53): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(61): error C3872: '0x3000': this character is not allowed in an identifier
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(62): error C3872: '0x3000': this character is not allowed in an identifier
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(63): error C2146: syntax error : missing ';' before identifier ' '
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(63): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(63): error C2086: 'int ' : redefinition
1> c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(53) : see declaration of ' '
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(63): error C2144: syntax error : 'int' should be preceded by ';'
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(63): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(63): error C2086: 'int ' : redefinition
1> c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(53) : see declaration of ' '
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(78): error C3872: '0x3000': this character is not allowed in an identifier
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(79): error C2144: syntax error : 'int' should be preceded by ';'
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(79): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(79): error C2086: 'int ' : redefinition
1> c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(53) : see declaration of ' '
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(102): error C3872: '0x3000': this character is not allowed in an identifier
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(103): error C2143: syntax error : missing ';' before 'if'
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(108): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(117): error C3872: '0x3000': this character is not allowed in an identifier
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(118): error C2144: syntax error : 'int' should be preceded by ';'
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(118): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(118): error C2086: 'int ' : redefinition
1> c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(53) : see declaration of ' '
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(120): error C3872: '0x3000': this character is not allowed in an identifier
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(121): error C3872: '0x3000': this character is not allowed in an identifier
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(122): error C2146: syntax error : missing ';' before identifier ' '
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(122): error C2143: syntax error : missing ';' before 'for'
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(136): error C3872: '0x3000': this character is not allowed in an identifier
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(137): error C2143: syntax error : missing ';' before 'return'
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(153): error C3872: '0x3000': this character is not allowed in an identifier
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(154): error C2144: syntax error : 'int' should be preceded by ';'
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(154): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(154): error C2086: 'int ' : redefinition
1> c:\documents and settings\schon\my documents\visual studio 2010\projects\final project datamax inc\final project datamax inc\final project datamax inc.cpp(53) : see declaration of ' '

Everything compiled fine for me after I removed the stray escapees.

Btw, TotalOvertimeHours does nothing you initialize it once and call it later. But no value ever gets assigned to it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.