GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Mar-2005, 21:05
leanieleanz leanieleanz is offline
New Member
 
Join Date: Mar 2005
Posts: 10
leanieleanz is on a distinguished road
Exclamation

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:
CPP / C++ / C Code:
#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++]
  #2  
Old 08-Mar-2005, 00:32
nopurpose nopurpose is offline
New Member
 
Join Date: Jan 2005
Posts: 5
nopurpose is on a distinguished road
Replace string empName = " "; with empName = " ";

It also seems that your function declaration for employeeFile doesn't match the prototype at the top of the code. You'll need to correct that.
 
 

Recent GIDBlogWriting a book by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] GUI programming with FLTK dsmith FLTK Forum 10 03-Oct-2005 15:41
What is "Ambigious symbol" ??*( a compilation error) small_ticket C++ Forum 2 07-Jan-2005 21:10
Error C2146: syntax error : missing ',' before identifier 'C4' mattchew008 C++ Forum 2 19-Dec-2004 06:06
Can enum have same name as class? crystalattice C++ Forum 3 08-Dec-2004 16:43
OpenGL always reports error mvt OpenGL Programming 2 04-Jun-2004 06:42

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:10.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.