B
BinWang85
The following is the code:
#include <iostream.h>
#include <math.h> //needed for decimal calculations
int main()
{
int employee_num;
double FetchHours(void);
double FetchTotalSales(void);
double CalcBasePay(double);
double CalcCommisionPay(double);
double CalcPayBeforeTax(double);
double CalcTax(double);
double CalcNetPay(double);
char DispResults(void);
char display;
double W_sales, hours, sales_comm, base_pay;
double pay_before_tax, tax_paid, net_pay; //assigned double for money
(decimals)
cout << "Please provide the following information \n";
cout << "Employee number: \n";
cin >> employee_num;
if (employee_num < 0){
cout << "Incorrect input for employee number\n"; //error check for
negative number
return(1);
}
hours = FetchHours();
if (hours < 0) {
cout << "Incorrect input for hours\n"; //error check for negative
number
return(1);
}
W_sales = FetchTotalSales();
if (W_sales < 0) {
cout << "Incorrect input for weekly sales\n"; //error check for
negative number
return(1);
}
base_pay = CalcBasePay(hours);
sales_comm = CalcCommisionPay(W_sales);
pay_before_tax = CalcPayBeforeTax(base_pay);
tax_paid = CalcTax(pay_before_tax);
net_pay = CalcNetPay(tax_paid);
display = DispResults();
return 0;
}
double FetchHours()
{
double hours;
cout << "Hours worked per week: \n";
cin >> hours;
return hours;
}
double FetchTotalSales()
{
double W_sales;
cout << "Weekly sales: \n";
cin >> W_sales;
return W_sales;
}
double CalcBasePay()
{
double hours;
double base_pay;
double base_rate = 23.00;
base_pay=base_rate*hours;
return base_pay;
}
double CalcCommisionPay()
{
double W_sales, sales_comm;
if (W_sales <= 2500)
sales_comm=W_sales*0.1500; //calcuate sales commission if weekly
sales is
//less than 2500 with 15% rate of weekly sales
else if (W_sales > 2500)
sales_comm=W_sales*0.25; //with 25% rate of weekly sales
return sales_comm;
}
int CalcPayBeforeTax()
{
double pay_before_tax, sales_comm, base_pay;
pay_before_tax=base_pay+sales_comm;
return pay_before_tax;
}
int CalcTax()
{
double pay_before_tax, tax_paid;
if (pay_before_tax > 3000)
tax_paid=pay_before_tax*0.30; //calculate tax paid for pay before tax
over 3000
else if (pay_before_tax < 1000)
tax_paid=pay_before_tax*0.10; //calculate tax paid for pay before tax
under 1000
else
tax_paid=pay_before_tax*0.20; //calculate tax paid for any other
amount of pay before tax
return tax_paid;
}
int CalcNetPay()
{
double net_pay, pay_before_tax, tax_paid;
net_pay=pay_before_tax-tax_paid;
return net_pay;
}
void DispResults()
{
int employee_num;
double base_pay;
double sales_comm;
double pay_before_tax;
double tax_paid;
double net_pay;
cout << "Employee number: " <<employee_num << "\n";
cout << "Base pay: $"<<base_pay<<"\n";
cout << "Sales Commission: $"<<sales_comm<<"\n";
cout << "Pay before tax: $"<<pay_before_tax<<"\n";
cout << "Tax paid: $"<<tax_paid<<"\n";
cout << "Net pay: $"<<net_pay<<"\n";
}
The errors I get are:
Deleting intermediate files and output files for project 'Exercise8 -
Win32 Debug'.
--------------------Configuration: Exercise8 - Win32
Debug--------------------
Compiling...
Exercise8.cpp
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(110) :
warning C4244: 'return' : conversion from 'double' to 'int', possible
loss of data
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(122) :
warning C4244: 'return' : conversion from 'double' to 'int', possible
loss of data
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(129) :
warning C4244: 'return' : conversion from 'double' to 'int', possible
loss of data
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(91) :
warning C4700: local variable 'hours' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(98) :
warning C4700: local variable 'W_sales' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(109) :
warning C4700: local variable 'base_pay' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(109) :
warning C4700: local variable 'sales_comm' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(116) :
warning C4700: local variable 'pay_before_tax' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(128) :
warning C4700: local variable 'pay_before_tax' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(128) :
warning C4700: local variable 'tax_paid' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(141) :
warning C4700: local variable 'employee_num' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(142) :
warning C4700: local variable 'base_pay' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(143) :
warning C4700: local variable 'sales_comm' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(144) :
warning C4700: local variable 'pay_before_tax' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(145) :
warning C4700: local variable 'tax_paid' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(146) :
warning C4700: local variable 'net_pay' used without having been
initialized
Linking...
Exercise8.obj : error LNK2001: unresolved external symbol "char __cdecl
DispResults(void)" (?DispResults@@YADXZ)
Exercise8.obj : error LNK2001: unresolved external symbol "double
__cdecl CalcNetPay(double)" (?CalcNetPay@@YANN@Z)
Exercise8.obj : error LNK2001: unresolved external symbol "double
__cdecl CalcTax(double)" (?CalcTax@@YANN@Z)
Exercise8.obj : error LNK2001: unresolved external symbol "double
__cdecl CalcPayBeforeTax(double)" (?CalcPayBeforeTax@@YANN@Z)
Exercise8.obj : error LNK2001: unresolved external symbol "double
__cdecl CalcCommisionPay(double)" (?CalcCommisionPay@@YANN@Z)
Exercise8.obj : error LNK2001: unresolved external symbol "double
__cdecl CalcBasePay(double)" (?CalcBasePay@@YANN@Z)
Debug/Exercise8.exe : fatal error LNK1120: 6 unresolved externals
Error executing link.exe.
Exercise8.exe - 7 error(s), 16 warning(s)
Can someone suggest a solution to my errors, thanks
#include <iostream.h>
#include <math.h> //needed for decimal calculations
int main()
{
int employee_num;
double FetchHours(void);
double FetchTotalSales(void);
double CalcBasePay(double);
double CalcCommisionPay(double);
double CalcPayBeforeTax(double);
double CalcTax(double);
double CalcNetPay(double);
char DispResults(void);
char display;
double W_sales, hours, sales_comm, base_pay;
double pay_before_tax, tax_paid, net_pay; //assigned double for money
(decimals)
cout << "Please provide the following information \n";
cout << "Employee number: \n";
cin >> employee_num;
if (employee_num < 0){
cout << "Incorrect input for employee number\n"; //error check for
negative number
return(1);
}
hours = FetchHours();
if (hours < 0) {
cout << "Incorrect input for hours\n"; //error check for negative
number
return(1);
}
W_sales = FetchTotalSales();
if (W_sales < 0) {
cout << "Incorrect input for weekly sales\n"; //error check for
negative number
return(1);
}
base_pay = CalcBasePay(hours);
sales_comm = CalcCommisionPay(W_sales);
pay_before_tax = CalcPayBeforeTax(base_pay);
tax_paid = CalcTax(pay_before_tax);
net_pay = CalcNetPay(tax_paid);
display = DispResults();
return 0;
}
double FetchHours()
{
double hours;
cout << "Hours worked per week: \n";
cin >> hours;
return hours;
}
double FetchTotalSales()
{
double W_sales;
cout << "Weekly sales: \n";
cin >> W_sales;
return W_sales;
}
double CalcBasePay()
{
double hours;
double base_pay;
double base_rate = 23.00;
base_pay=base_rate*hours;
return base_pay;
}
double CalcCommisionPay()
{
double W_sales, sales_comm;
if (W_sales <= 2500)
sales_comm=W_sales*0.1500; //calcuate sales commission if weekly
sales is
//less than 2500 with 15% rate of weekly sales
else if (W_sales > 2500)
sales_comm=W_sales*0.25; //with 25% rate of weekly sales
return sales_comm;
}
int CalcPayBeforeTax()
{
double pay_before_tax, sales_comm, base_pay;
pay_before_tax=base_pay+sales_comm;
return pay_before_tax;
}
int CalcTax()
{
double pay_before_tax, tax_paid;
if (pay_before_tax > 3000)
tax_paid=pay_before_tax*0.30; //calculate tax paid for pay before tax
over 3000
else if (pay_before_tax < 1000)
tax_paid=pay_before_tax*0.10; //calculate tax paid for pay before tax
under 1000
else
tax_paid=pay_before_tax*0.20; //calculate tax paid for any other
amount of pay before tax
return tax_paid;
}
int CalcNetPay()
{
double net_pay, pay_before_tax, tax_paid;
net_pay=pay_before_tax-tax_paid;
return net_pay;
}
void DispResults()
{
int employee_num;
double base_pay;
double sales_comm;
double pay_before_tax;
double tax_paid;
double net_pay;
cout << "Employee number: " <<employee_num << "\n";
cout << "Base pay: $"<<base_pay<<"\n";
cout << "Sales Commission: $"<<sales_comm<<"\n";
cout << "Pay before tax: $"<<pay_before_tax<<"\n";
cout << "Tax paid: $"<<tax_paid<<"\n";
cout << "Net pay: $"<<net_pay<<"\n";
}
The errors I get are:
Deleting intermediate files and output files for project 'Exercise8 -
Win32 Debug'.
--------------------Configuration: Exercise8 - Win32
Debug--------------------
Compiling...
Exercise8.cpp
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(110) :
warning C4244: 'return' : conversion from 'double' to 'int', possible
loss of data
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(122) :
warning C4244: 'return' : conversion from 'double' to 'int', possible
loss of data
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(129) :
warning C4244: 'return' : conversion from 'double' to 'int', possible
loss of data
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(91) :
warning C4700: local variable 'hours' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(98) :
warning C4700: local variable 'W_sales' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(109) :
warning C4700: local variable 'base_pay' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(109) :
warning C4700: local variable 'sales_comm' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(116) :
warning C4700: local variable 'pay_before_tax' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(128) :
warning C4700: local variable 'pay_before_tax' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(128) :
warning C4700: local variable 'tax_paid' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(141) :
warning C4700: local variable 'employee_num' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(142) :
warning C4700: local variable 'base_pay' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(143) :
warning C4700: local variable 'sales_comm' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(144) :
warning C4700: local variable 'pay_before_tax' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(145) :
warning C4700: local variable 'tax_paid' used without having been
initialized
c:\bin\algonquin\programmingcst8110\exercise8\exercise8.cpp(146) :
warning C4700: local variable 'net_pay' used without having been
initialized
Linking...
Exercise8.obj : error LNK2001: unresolved external symbol "char __cdecl
DispResults(void)" (?DispResults@@YADXZ)
Exercise8.obj : error LNK2001: unresolved external symbol "double
__cdecl CalcNetPay(double)" (?CalcNetPay@@YANN@Z)
Exercise8.obj : error LNK2001: unresolved external symbol "double
__cdecl CalcTax(double)" (?CalcTax@@YANN@Z)
Exercise8.obj : error LNK2001: unresolved external symbol "double
__cdecl CalcPayBeforeTax(double)" (?CalcPayBeforeTax@@YANN@Z)
Exercise8.obj : error LNK2001: unresolved external symbol "double
__cdecl CalcCommisionPay(double)" (?CalcCommisionPay@@YANN@Z)
Exercise8.obj : error LNK2001: unresolved external symbol "double
__cdecl CalcBasePay(double)" (?CalcBasePay@@YANN@Z)
Debug/Exercise8.exe : fatal error LNK1120: 6 unresolved externals
Error executing link.exe.
Exercise8.exe - 7 error(s), 16 warning(s)
Can someone suggest a solution to my errors, thanks