Keep getting this error in my assignment so confused \" Undefined symbols for ar
ID: 3728753 • Letter: K
Question
Keep getting this error in my assignment so confused
"
Undefined symbols for architecture x86_64:
"output(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, double, double, double, char, int, int)", referenced from:
_main in payroll.o
"getData(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, double, double, int, char, double)", referenced from:
_main in payroll.o
"calcData(int, double, double, double, int, int, int, int, double, char)", referenced from:
_main in payroll.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
"
//
// payroll.cpp
// Lab 5 Payroll
//
//
/*Write a C++ program to calculate a person’s pay stub assuming paid on a monthly basis.
Your design must be according to the structure chart given here. That is main() will call input function, calculation function, and output function in that order. */
#include
#include
#include
using namespace std;
void getData(string& employeename, double hourlywage,double hoursworked,int withholding,char maritalstat,double previousyearinc);
double calcData(int witholding, double hoursworked, double hourlywage, double previousyearinc, int ficatax, int currentearned, int incometax, int check,double tempnumb,char maritialstat);
void output(string employeename, double currentearned, double hoursworked,double withholding, char maritalstat, int ficatax, int check);
//output of signature
int main ()
{
string employeename;
char maritalstat = '';
double hoursworked = 0.0, withholding = 0.0, hourlywage = 0.0, previousyearinc = 0.0;
int ficatax = 0, currentearned = 0, incometax = 0, check = 0, tempnumb = 0;
getData(employeename, hourlywage, hoursworked, withholding, maritalstat, previousyearinc);
calcData(withholding, hoursworked, hourlywage, previousyearinc, ficatax, currentearned, incometax, check, tempnumb, maritalstat);
output(employeename, currentearned, hoursworked, withholding, maritalstat, ficatax, check);
return 0;
}
void Signature()
{
cout << "Jess Hutchins " << endl;
cout << "jess@hnhtraining.com, jesshutch@mac.com" << endl;
cout << "Lab 4"<
}
//functions prototype
double getData(string employename, double hourlywage, double hoursworked, double withholding, char maritalstat, double previousyearinc)
{
cout << "What is your name? "<
getline(cin, employename);
cout << "What is your hourly wage? "<
cin >> hourlywage;
cout << "How many hours did you work? "<
cin >> hoursworked;
cout << "What is your current with holding"<
cin >> withholding;
cout << "What is your Maritial Status (M)(S) "<
cin >> maritalstat;
cout << "What is your previous year earnings?"<
cin >> previousyearinc;
return 0;
}
//int ficatax, currentearned, incometax, check, tempnumb;
double calcData(int witholding, double& hoursworked, double hourlywage, double previousyearinc, int ficatax, int currentearned, int incometax, int check,int tempnumb,char maritialstat)
{
incometax = 0;
if(hoursworked>40)
currentearned = hourlywage*hoursworked*1.5;
else
currentearned = hourlywage*hoursworked;
if(previousyearinc<128700)
ficatax=currentearned*0.062;
else
ficatax=0;
tempnumb = currentearned - witholding*345.80;
if(maritialstat == 'S' || maritialstat == 's'){
if(tempnumb>308 && tempnumb<=1102)
incometax=tempnumb*0.1;
if(tempnumb>1102 && tempnumb<=3533)
incometax=tempnumb*0.12 + 79.40;
if(tempnumb>3533 && tempnumb<=7183)
incometax=tempnumb*0.22 + 371.12;
if(tempnumb>7183 && tempnumb<=13433)
incometax=tempnumb*0.24 + 1174.12;
if(tempnumb>13433 && tempnumb<=16975)
incometax=tempnumb*0.32 + 2674.12;
if(tempnumb>16975 && tempnumb<=41975)
incometax=tempnumb*0.35 + 3807.56;
if(tempnumb>41975)
incometax=tempnumb*0.37 + 12577.56;
}
if(maritialstat == 'M' || maritialstat == 'm'){
if(tempnumb>963 && tempnumb<=2550)
incometax=tempnumb*0.1;
if(tempnumb>2550 && tempnumb<=7413)
incometax=tempnumb*0.12 + 158.70;
if(tempnumb>7413 && tempnumb<=14713)
incometax=tempnumb*0.22 + 742.26;
if(tempnumb>14713 && tempnumb<=27213)
incometax=tempnumb*0.24 + 2348.26;
if(tempnumb>27213 && tempnumb<=34296)
incometax=tempnumb*0.32 + 5348.26;
if(tempnumb>34296 && tempnumb<=50963)
incometax=tempnumb*0.35 + 7614.82;
if(tempnumb>50963)
incometax=tempnumb*0.37 + 13448.27;
}
previousyearinc = previousyearinc+currentearned;
check = currentearned - ficatax - incometax;
return 0;
}
/*
Pre: subtotal = subtotal of order
tax = amount of tax
total = total of order
Post: Nothing
Purpose: output order
*/
/* output(currentearned, hoursworked, withholding, maritalstat, ficatax, check);*/
void output(string& employeename, double currentearned, double hoursworked,double withholding, char maritalstat, int ficatax, int check)
{
cout<<" Name:";
cout<
cout<<" Current Earnings";
cout<
cout<<" Year to Date";
cout<
cout<<" Fica:";
cout<
cout<<" Income Tax Withheld:";
cout<
cout<<" Amount of check:";
cout<
return;
}
Explanation / Answer
The errors were with the data types. Function was declared to have parameter int but in the implementation it was double. Somewhere a reference (&) was declared and in the implementation there was not reference.
Note a function parameter is passed as reference i.e has a preceding & with it whenever that parameter has to be returned with some updated value. Plus in lieu of the calculations in the code, declaring any variable as int would cause data loss. I have made the required changes. Please check the output function. The question had it stripped in a vague manner, you might need to modify it as per your needs.
Regards
Code
//
// payroll.cpp
// Lab 5 Payroll
//
//
/*Write a C++ program to calculate a person’s pay stub assuming paid on a monthly basis.
Your design must be according to the structure chart given here. That is main() will call input function, calculation function, and output function in that order. */
#include <iostream>
// #include <
// #include
using namespace std;
double getData(string& employeename, double& hourlywage,double& hoursworked,double& withholding,char& maritalstat,double& previousyearinc);
double calcData(double& witholding, double& hoursworked, double& hourlywage, double& previousyearinc, double& ficatax, double& currentearned, double& incometax, double& check,double& tempnumb,char& maritialstat);
void output(string employeename, double currentearned, double hoursworked,double withholding, char maritalstat, double ficatax, double check, double incometax);
//output of signature
int main () {
string employeename;
char maritalstat = '';
double hoursworked = 0.0, withholding = 0.0, hourlywage = 0.0, previousyearinc = 0.0;
double ficatax = 0, currentearned = 0, incometax = 0, check = 0, tempnumb = 0;
getData(employeename, hourlywage, hoursworked, withholding, maritalstat, previousyearinc);
calcData(withholding, hoursworked, hourlywage, previousyearinc, ficatax, currentearned, incometax, check, tempnumb, maritalstat);
output(employeename, currentearned, hoursworked, withholding, maritalstat, ficatax, check, incometax);
return 0;
}
void Signature()
{
cout << "Jess Hutchins " << endl;
cout << "jess@hnhtraining.com, jesshutch@mac.com" << endl;
cout << "Lab 4"<< endl;
}
//functions prototype
double getData(string& employename, double& hourlywage, double& hoursworked, double& withholding, char& maritalstat, double& previousyearinc)
{
cout << "What is your name? "<<endl;
getline(cin, employename);
cout << "What is your hourly wage? "<
cin >> hourlywage;
cout << "How many hours did you work? "<<endl;
cin >> hoursworked;
cout << "What is your current with holding"<<endl;
cin >> withholding;
cout << "What is your Maritial Status (M)(S) "<<endl;
cin >> maritalstat;
cout << "What is your previous year earnings?"<<endl;
cin >> previousyearinc;
return 0;
}
//double ficatax, currentearned, incometax, check, tempnumb;
double calcData(double& witholding, double& hoursworked, double& hourlywage, double& previousyearinc, double& ficatax, double& currentearned, double& incometax, double& check,double& tempnumb,char& maritialstat)
{
incometax = 0;
if(hoursworked>40)
currentearned = hourlywage*hoursworked*1.5;
else
currentearned = hourlywage*hoursworked;
if(previousyearinc<128700)
ficatax=currentearned*0.062;
else
ficatax=0;
tempnumb = currentearned - witholding*345.80;
if(maritialstat == 'S' || maritialstat == 's'){
if(tempnumb>308 && tempnumb<=1102)
incometax=tempnumb*0.1;
if(tempnumb>1102 && tempnumb<=3533)
incometax=tempnumb*0.12 + 79.40;
if(tempnumb>3533 && tempnumb<=7183)
incometax=tempnumb*0.22 + 371.12;
if(tempnumb>7183 && tempnumb<=13433)
incometax=tempnumb*0.24 + 1174.12;
if(tempnumb>13433 && tempnumb<=16975)
incometax=tempnumb*0.32 + 2674.12;
if(tempnumb>16975 && tempnumb<=41975)
incometax=tempnumb*0.35 + 3807.56;
if(tempnumb>41975)
incometax=tempnumb*0.37 + 12577.56;
}
if(maritialstat == 'M' || maritialstat == 'm'){
if(tempnumb>963 && tempnumb<=2550)
incometax=tempnumb*0.1;
if(tempnumb>2550 && tempnumb<=7413)
incometax=tempnumb*0.12 + 158.70;
if(tempnumb>7413 && tempnumb<=14713)
incometax=tempnumb*0.22 + 742.26;
if(tempnumb>14713 && tempnumb<=27213)
incometax=tempnumb*0.24 + 2348.26;
if(tempnumb>27213 && tempnumb<=34296)
incometax=tempnumb*0.32 + 5348.26;
if(tempnumb>34296 && tempnumb<=50963)
incometax=tempnumb*0.35 + 7614.82;
if(tempnumb>50963)
incometax=tempnumb*0.37 + 13448.27;
}
previousyearinc = previousyearinc+currentearned;
check = currentearned - ficatax - incometax;
return 0;
}
/*
Pre: subtotal = subtotal of order
tax = amount of tax
total = total of order
Post: Nothing
Purpose: output order
*/
/* output(currentearned, hoursworked, withholding, maritalstat, ficatax, check);*/
void output(string employeename, double currentearned, double hoursworked,double withholding, char maritalstat, double ficatax, double check, double incometax)
{
cout<<" Name:" <<employeename;
cout<<" Current Earnings:" <<currentearned;
cout<<" Withholdings:" <<withholding;
cout<<" Fica:"<<ficatax;
cout<<" Income Tax Withheld:"<<incometax;
cout<<" Amount of check:"<<check;
return;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.