This is a program on finding a weekly payroll program. So as I was compiling the program it came up with 2 warnings saying "not all control paths return a value" (somewhere between the married and single tax). So i am not sure what is wrong. I'm not sure if i should just use 1 function to find the federal income tax, which is what the married and single tax function is doing, or two. I'm trying to use the 2 functions to calculate if the employee's status is married it will do this and if employee's status is single it will do that.
This is the program:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;
#include <iomanip>
using std::setprecision;
using std::setiosflags;
using std::setw;
#include <cmath>
double earnings (double, double);
double yrEarnings (double, double);
double FICAtax (double, double, double);
double wkIncome (double, int);
double marriedTax (int, double);
double singleTax (double, double);
int main()
{
int status, exempt;
double hrwage, hrs, prEarnings;
char fname [25], lname [25];
for (int count=1; count <= 3; count++) {
cout << "Enter first & last name: ";
cin >> fname >> lname;
cout << "Enter hourly wage: ";
cin >> hrwage;
cout << "Enter hours worked: ";
cin >> hrs;
cout << "Enter previous earnings: ";
cin >> prEarnings;
cout << "Enter marital status (1=married,
2=single): ";
cin >> status;
cout << "Enter withholding exemptions: ";
cin >> exempt;
cout << "\t\tCurrent" << setw(14) << "Yr.
to Date"
<< setw(7) << "FICA" << "\tIncome"
<< "\tCheck" << "\nName"
<< "\t\tEarnings" << setw(10)
<< "Earnings" << "\tTaxes" << "\tTax
Wh." << "\tAmount" << endl;
cout << setiosflags (ios::fixed |
ios::showpoint)
<< setprecision (2);
cout << fname << setw(2) << lname << setw
(10) << "$" << earnings(hrwage, hrs)
<< setw(5) << "$" << yrEarnings
(earnings(hrwage, hrs), prEarnings)
<< setw(5) << "$" << FICAtax(earnings
(hrwage, hrs), yrEarnings(earnings
(hrwage, hrs), prEarnings), prEarnings)
<< setw(5) << "$" << wkIncome(earnings
(hrwage, hrs), exempt)
<< setw(5) << "$" << marriedTax
(status, wkIncome(earnings(hrwage,
hrs), exempt))
<< setw(5) << "$" << singleTax(status,
wkIncome(earnings(hrwage, hrs),
exempt))
<< endl;
}
return 0;
}
double earnings (double hrwage, double hrs)
{
if (hrs >= 40)
return (hrwage*40) + (hrs - 40) * 1.5 * hrwage;
else
return hrwage*hrs;
}
double yrEarnings (double earnings, double prEarnings)
{
return earnings+prEarnings;
}
double FICAtax (double earnings, double prEarnings, double yrEarnings)
{
if (prEarnings >= 68400)
return 0 + earnings * 0.0145;
else if (yrEarnings >= 68400)
return (68400 - prEarnings) * 0.062;
else
return 0.062*earnings + 0.0145*earnings;
}
double wkIncome (double earnings, int exempt)
{
return (earnings - (exempt * 51.92));
}
double marriedTax (int status, double wkIncome)
{
if (status == 1)
if (wkIncome >= 0 && wkIncome <= 124)
return 0;
else if (wkIncome >= 124 && wkIncome <= 899)
return 0.15 * wkIncome - 124;
else if (wkIncome >= 899 && wkIncome <= 1855)
return 116.25 + (0.28 * wkIncome - 899);
else if (wkIncome >= 1855 && wkIncome <= 3084)
return 383.93 + (0.31 * wkIncome - 1855);
else if (wkIncome >= 3084 && wkIncome <= 5439)
return 764.92 + (0.36 * wkIncome - 3084);
else
return 1612.72 + (0.396 * wkIncome - 5439);
}
double singleTax (int status, double wkIncome)
{
if (status == 2)
if (wkIncome >= 0 && wkIncome <= 51)
return 0;
else if (wkIncome >= 51 && wkIncome <= 517)
return 0.15 * wkIncome - 51;
else if (wkIncome >= 517 && wkIncome <= 1105)
return 69.90 + (0.28 * wkIncome - 517);
else if (wkIncome >= 1105 && wkIncome <= 2493)
return 234.54 + (0.31 * wkIncome - 1105);
else if (wkIncome >= 2493 && wkIncome <= 5385)
return 664.82 + (0.36 * wkIncome - 2493);
else if (wkIncome >= 5385)
return 1705.94 + (0.396 * wkIncome - 5385);
}
This is the program:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;
#include <iomanip>
using std::setprecision;
using std::setiosflags;
using std::setw;
#include <cmath>
double earnings (double, double);
double yrEarnings (double, double);
double FICAtax (double, double, double);
double wkIncome (double, int);
double marriedTax (int, double);
double singleTax (double, double);
int main()
{
int status, exempt;
double hrwage, hrs, prEarnings;
char fname [25], lname [25];
for (int count=1; count <= 3; count++) {
cout << "Enter first & last name: ";
cin >> fname >> lname;
cout << "Enter hourly wage: ";
cin >> hrwage;
cout << "Enter hours worked: ";
cin >> hrs;
cout << "Enter previous earnings: ";
cin >> prEarnings;
cout << "Enter marital status (1=married,
2=single): ";
cin >> status;
cout << "Enter withholding exemptions: ";
cin >> exempt;
cout << "\t\tCurrent" << setw(14) << "Yr.
to Date"
<< setw(7) << "FICA" << "\tIncome"
<< "\tCheck" << "\nName"
<< "\t\tEarnings" << setw(10)
<< "Earnings" << "\tTaxes" << "\tTax
Wh." << "\tAmount" << endl;
cout << setiosflags (ios::fixed |
ios::showpoint)
<< setprecision (2);
cout << fname << setw(2) << lname << setw
(10) << "$" << earnings(hrwage, hrs)
<< setw(5) << "$" << yrEarnings
(earnings(hrwage, hrs), prEarnings)
<< setw(5) << "$" << FICAtax(earnings
(hrwage, hrs), yrEarnings(earnings
(hrwage, hrs), prEarnings), prEarnings)
<< setw(5) << "$" << wkIncome(earnings
(hrwage, hrs), exempt)
<< setw(5) << "$" << marriedTax
(status, wkIncome(earnings(hrwage,
hrs), exempt))
<< setw(5) << "$" << singleTax(status,
wkIncome(earnings(hrwage, hrs),
exempt))
<< endl;
}
return 0;
}
double earnings (double hrwage, double hrs)
{
if (hrs >= 40)
return (hrwage*40) + (hrs - 40) * 1.5 * hrwage;
else
return hrwage*hrs;
}
double yrEarnings (double earnings, double prEarnings)
{
return earnings+prEarnings;
}
double FICAtax (double earnings, double prEarnings, double yrEarnings)
{
if (prEarnings >= 68400)
return 0 + earnings * 0.0145;
else if (yrEarnings >= 68400)
return (68400 - prEarnings) * 0.062;
else
return 0.062*earnings + 0.0145*earnings;
}
double wkIncome (double earnings, int exempt)
{
return (earnings - (exempt * 51.92));
}
double marriedTax (int status, double wkIncome)
{
if (status == 1)
if (wkIncome >= 0 && wkIncome <= 124)
return 0;
else if (wkIncome >= 124 && wkIncome <= 899)
return 0.15 * wkIncome - 124;
else if (wkIncome >= 899 && wkIncome <= 1855)
return 116.25 + (0.28 * wkIncome - 899);
else if (wkIncome >= 1855 && wkIncome <= 3084)
return 383.93 + (0.31 * wkIncome - 1855);
else if (wkIncome >= 3084 && wkIncome <= 5439)
return 764.92 + (0.36 * wkIncome - 3084);
else
return 1612.72 + (0.396 * wkIncome - 5439);
}
double singleTax (int status, double wkIncome)
{
if (status == 2)
if (wkIncome >= 0 && wkIncome <= 51)
return 0;
else if (wkIncome >= 51 && wkIncome <= 517)
return 0.15 * wkIncome - 51;
else if (wkIncome >= 517 && wkIncome <= 1105)
return 69.90 + (0.28 * wkIncome - 517);
else if (wkIncome >= 1105 && wkIncome <= 2493)
return 234.54 + (0.31 * wkIncome - 1105);
else if (wkIncome >= 2493 && wkIncome <= 5385)
return 664.82 + (0.36 * wkIncome - 2493);
else if (wkIncome >= 5385)
return 1705.94 + (0.396 * wkIncome - 5385);
}