Quick help - redefinition error
I am trying to code a program that will read input from three files and calculate a person's weekly paycheck.
I am having toubles with the initialize function. I get an error when I try to initialize the empName string variable. I need it to be initialized so I can use it in main to call other functions. *Look for asteriks in comment for error location*. If any one would be so kind to let me know what my mistake is and how I can correct it. Thanks! Code as follows:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
void employeeFile(int& id, char& empType, double& empRate, double& emp401K, int& empDependents, double& empYTDHours, double& empYTDGross, string& empName);
void hoursFile(int& id, double& hours, ifstream& inHoursFile, ofstream& outHoursFile);
void taxesFile(char& def, double& rate);
void initialize(int& id, char& empType, double& empRate, double& emp401K, int& empDependents, double& empYTDHours, double& empYTDGross, string& empName, double& hours, char& def, double& rate);
int main()
{
//declare variables
int id;
char empType;
double empRate;
double emp401K;
int empDependents;
double empYTDHours;
double empYTDGross;
string empName;
double hours;
char def;
double rate;
initialize(id, empType, empRate, emp401K, empDependents, empYTDHours, empYTDGross, empName, hours, def, rate);
employeeFile(id, empType, empRate, emp401K, empDependents, empYTDHours, empYTDGross, empName);
//hoursFile();
//taxesFile();
return 0;
}
void initialize(int& id, char& empType, double& empRate, double& emp401K, int& empDependents, double& empYTDHours, double& empYTDGross, string& empName, double& hours, char& def, double& rate)
{
id = 0;
empType = ' ';
empRate = 0;
emp401K = 0;
empDependents = 0;
empYTDHours = 0;
empYTDGross = 0;
string empName = " "; //*****THIS IS WHERE I GET MY ERROR*****
hours = 0;
def = ' ';
rate = 0;
}
void employeeFile(int& id, char empType, double empRate, double emp401K, int empDependents, double empYTDHours, double empYTDGross, string empName)
{
//declare employee file variables
ifstream inEmpFile;
ofstream outEmpFile;
/*int id;
char empType;
double empRate;
double emp401K;
int empDependents;
double empYTDHours;
double empYTDGross;
string empName;*/
//get info for employee file
inEmpFile.open("C:\\Documents and Settings\\Lena Esho\\Desktop\\Final Project\\Final Project\\ProjectDraft\\Employee.txt");
outEmpFile.open("C:\\Documents and Settings\\Lena Esho\\Desktop\\Final Project\\Final Project\\ProjectDraft\\Register.txt");
//inEmpFile.open("C:\\Documents and Settings\\Leanie\\My Documents\\College Stuff\\C++\\Final Project\\ProjectDraft\\Employee.txt");
//outEmpFile.open("C:\\Documents and Settings\\Leanie\\My Documents\\College Stuff\\C++\\Final Project\\ProjectDraft\\Register.txt");
outEmpFile << fixed << showpoint;
outEmpFile << setprecision(2);
cout << "Processing employee data..." << endl;
//get employee id
inEmpFile >> id;
while (inEmpFile)
{
outEmpFile << "\nEmployee ID: " << id << endl;
//get employee type
inEmpFile >> empType;
//outFile << "Employee Type: " << empType << endl;
//get employee pay rate
inEmpFile >> empRate;
outEmpFile << "Employee Pay Rate: " << empRate << endl;
//get 401k deductions
inEmpFile >> emp401K;
outEmpFile << "Employee 401k Deduction: " << emp401K << endl;
//get dependents
inEmpFile >> empDependents;
outEmpFile << "Employee Dependents: " << empDependents << endl;
//get YTD hours
inEmpFile >> empYTDHours;
outEmpFile << "Employee YTD Hours: " << empYTDHours << endl;
//get YTD gross
inEmpFile >> empYTDGross;
outEmpFile << "Employee YTD Gross " << empYTDGross << endl;
//get employee name
getline(inEmpFile, empName);
outEmpFile << "Employee Name: " << empName << endl;
//get employee id
inEmpFile >> id;
}
inEmpFile.close();
outEmpFile.close();
}
void hoursFile(int id, double hours)
{
//declare hours file variables
ifstream inHoursFile;
ofstream outHoursFile;
/*//int id;
double hours;*/
inHoursFile.open("C:\\Documents and Settings\\Lena Esho\\Desktop\\Final Project\\Final Project\\ProjectDraft\\Hours.txt");
outHoursFile.open("C:\\Documents and Settings\\Lena Esho\\Desktop\\Final Project\\Final Project\\ProjectDraft\\Register.txt");
//inHoursFile.open("C:\\Documents and Settings\\Leanie\\My Documents\\College Stuff\\C++\\Final Project\\ProjectDraft\\Hours.txt");
//outHoursFile.open("C:\\Documents and Settings\\Leanie\\My Documents\\College Stuff\\C++\\Final Project\\ProjectDraft\\Register.txt");
outHoursFile << fixed << showpoint;
outHoursFile << setprecision(2);
cout << "Processing hours data..." << endl;
//get employee id
inHoursFile >> id;
while(inHoursFile)
{
outHoursFile << "\nEmployee ID: " << id << endl;
//get hours worked
inHoursFile >> hours;
outHoursFile << "Employee hours worked: " << hours << endl;
//get employee id
inHoursFile >> id;
}
inHoursFile.close();
outHoursFile.close();
}
void taxesFile(char def, double rate)
{
//declare taxes file variables
ifstream inTaxesFile;
ofstream outTaxesFile;
/*char def;
double rate;*/
inTaxesFile.open("C:\\Documents and Settings\\Lena Esho\\Desktop\\Final Project\\Final Project\\ProjectDraft\\Taxes.txt");
outTaxesFile.open("C:\\Documents and Settings\\Lena Esho\\Desktop\\Final Project\\Final Project\\ProjectDraft\\Register.txt");
//inTaxesFile.open("C:\\Documents and Settings\\Leanie\\My Documents\\College Stuff\\C++\\Final Project\\ProjectDraft\\Taxes.txt");
//outTaxesFile.open("C:\\Documents and Settings\\Leanie\\My Documents\\College Stuff\\C++\\Final Project\\ProjectDraft\\Register.txt");
outTaxesFile << fixed << showpoint;
outTaxesFile << setprecision(2);
cout << "Processing taxes data..." << endl;
//get field type
inTaxesFile >> def;
while(inTaxesFile)
{
outTaxesFile << "\nField type: " << def << endl;
//get rate
inTaxesFile >> rate;
outTaxesFile << "Employee field value: " << rate << endl;
//get field type
inTaxesFile >> def;
}
inTaxesFile.close();
outTaxesFile.close();
}
Last edited by LuciWiz : 08-Mar-2005 at 01:10.
Reason: Please insert your C++ code between [c++] & [/c++]
|