Hi all,
I am very much a beginner and I'm struggling just to pass this class..so go easy on me. I keep getting this 1 error and I cannot figure out why. I'm sure it's something simple but I'm at a dead-end here.
This is the error I get, it points to the call to function 'display':

error C2664: 'display' : cannot convert parameter 1 from 'char [25]' to 'employee'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous

Code:

#include <iostream>
#include <iomanip> //Required for setw
#include <string>

using namespace std;

const int NAMES_SIZE = 25;
const int SSN_SIZE = 12;

//struct
struct employee{
    char firstName[NAMES_SIZE];
    char lastName[NAMES_SIZE];
    char ssn[12];
    char employeeType;
    double hours,
        rate;
};

//Function Prototypes
void getfirstName(char[25]);
void getlastName (char[25]);
void getssn (char[12]);
char getType();
double getHours();
double getRate();
double calculateGrossPay(double,double,char);
double calculateStateTax(double);
double calculateFederalTax(double);
double calculateNetPay(double,double,double);
void display(employee,employee,employee,employee,double,double,double,double);


int main(){

    employee emp;
    string empTypeStr;
    double pay;
        double nysTax;              //calculated NYS tax
    double fedTax;              //calculated fed tax
    double netPay;              //calculated net pay


    getfirstName(emp.firstName);
    getlastName(emp.lastName);
    getssn(emp.ssn);
    emp.employeeType = getType();
    emp.hours = getHours();
    emp.rate = getRate();
    pay = calculateGrossPay(emp.hours,emp.rate,emp.employeeType);
    nysTax = calculateStateTax(pay);
    fedTax = calculateFederalTax(pay);
    netPay = calculateNetPay(pay,fedTax,nysTax);
    display(emp.firstName,emp.lastName,emp.ssn,emp.employeeType,pay,fedTax,nysTax,netPay);
    } //end main

void getfirstName(char firstName[]){
    //prompt the user for the employee first name
    cout << "\nEnter your first name: (no spaces) ";
    //get the employee first name
    cin.getline(firstName,NAMES_SIZE);
    }//end function getfirstName

void getlastName(char lastName[]){
    //prompt the user for the employee last name
     cout << "Enter your last name: (no spaces) ";
    //get the employee last name
     cin.getline(lastName,NAMES_SIZE);
}//end function getlastName

void getssn (char ssn[]){
    //prompt the user for the employee social security number
     cout << "Enter your social security number: (xxx-xx-xxxx)  ";
     cin.getline(ssn,SSN_SIZE);
}//end function getssn

char getType(){
    //prompt for employee type
    char employeeType; 
    string empTypeStr;
    do {
         cout << "\nEnter \n";
         cout << setw(29) << "H for hourly employee \n";
         cout << setw(31) << "S for salaried employee \n";
         cout << setw(28) << "U for union employee \n";
         cin >> employeeType;
     }while ((employeeType != 'h')
         &&(employeeType != 'H')
         &&(employeeType != 's')
         &&(employeeType != 'S')
         &&(employeeType != 'u')
         &&(employeeType != 'U'));
        return employeeType;
}//end function getType


double getHours(){
    double hours;
    //prompt for the hours worked
    cout << "\nHow many hours did you work? ";
    cin >> hours;
    return hours;

}//end function getHours


double getRate(){
    //prompt for the pay rate per hour
    double rate;
    cout << "\nHow much do you get paid per hour? ";
    cin >> rate;
    return rate;
}//end function getRate


double calculateGrossPay(double hours,double rate,char employeeType){
    double pay;
    string empTypeStr;

        //***CALCULATE***
    //calculate the pay
    pay = hours * rate;
    if (employeeType == 'U' || employeeType == 'u') //Union pay calculation
        if (hours <= 40)
            pay = rate * hours;
        else
        pay = (40 * rate) + (hours - 40) * (rate * 1.5);

    return pay;
    }//end function calculateGrossPay


double calculateStateTax(double pay){
    double nysTax;
    const double NYS_RATE = 0.10;   //nys tax rate
    //calculate the nys tax
    nysTax = pay * NYS_RATE;

    return nysTax;
}//end function calculateStateTax


double calculateFederalTax(double pay){
    double fedTax;
    const double FED_RATE = 0.15;   //fed tax rate
    //calculate the fed tax
    fedTax = pay * FED_RATE;

    return fedTax;
}//end function calculateFederalTax


double calculateNetPay(double pay,double nysTax,double fedTax){
    double netPay;
    //calculate the net pay
    netPay = pay - nysTax - fedTax;

    return netPay;
}//end function calculateNetPay





void display(employee firstName,employee lastName,employee ssn,employee employeeType,double pay,double nysTax,double fedTax,double netPay){
    string empTypeStr;
    employee emp;
    //***OUTPUT***   
    //Display the results for the payroll

    cout << "\nPayroll for " << emp.firstName << " " << emp.lastName << endl;
    cout << "\nSSN: " << emp.ssn << endl;
    cout << "Employee Status: " << emp.employeeType << endl;
    cout << setprecision(2) << fixed;
    cout << "\nGross pay: \t$" << setw(10) << pay << endl;
    cout << "Federal Tax: \t$" << setw(10) << fedTax << endl;
    cout << "NYS Tax: \t$" << setw(10) << nysTax << endl;
    cout << "Net Pay: \t$" << setw(10) << netPay << endl;
}

Recommended Answers

All 4 Replies

The function prototype is incorrect. The first three parameters should be char*, not employee. The first three parameters in the function implementation are also incorrect. Change them to char* instead of employee.

The function prototype is incorrect. The first three parameters should be char*, not employee. The first three parameters in the function implementation are also incorrect. Change them to char* instead of employee.

Thanks for the reply. The instructions to this lab tell me to change those to employee because of the struct at the start of the program and to delete the existing declarations for these. If i change back to char it doesn't work. I can't say the instructor is the best at writing clear instructions but it's all I have to work with!

Then most likely what you want is this: void display(employee &emp,double pay,double nysTax,double fedTax,double netPay){ Since structure employee contains a several arrays and two doubles you only have to declare the employee parameter once. That is going to pass a reference to the entire structure, not just a given member variable.

Then most likely what you want is this: void display(employee &emp,double pay,double nysTax,double fedTax,double netPay){ Since structure employee contains a several arrays and two doubles you only have to declare the employee parameter once. That is going to pass a reference to the entire structure, not just a given member variable.

HALLELUJAH!!! It is working now. Thanks so much for your help. Now I can keep going. :-)

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.