Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weekly Payroll Program:::need help

Status
Not open for further replies.

hollaback

Technical User
Apr 8, 2003
6
US
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 << &quot;Enter first & last name: &quot;;
cin >> fname >> lname;
cout << &quot;Enter hourly wage: &quot;;
cin >> hrwage;
cout << &quot;Enter hours worked: &quot;;
cin >> hrs;
cout << &quot;Enter previous earnings: &quot;;
cin >> prEarnings;
cout << &quot;Enter marital status (1=married,
2=single): &quot;;
cin >> status;
cout << &quot;Enter withholding exemptions: &quot;;
cin >> exempt;


cout << &quot;\t\tCurrent&quot; << setw(14) << &quot;Yr.
to Date&quot;
<< setw(7) << &quot;FICA&quot; << &quot;\tIncome&quot;
<< &quot;\tCheck&quot; << &quot;\nName&quot;
<< &quot;\t\tEarnings&quot; << setw(10)
<< &quot;Earnings&quot; << &quot;\tTaxes&quot; << &quot;\tTax
Wh.&quot; << &quot;\tAmount&quot; << endl;
cout << setiosflags (ios::fixed |
ios::showpoint)
<< setprecision (2);

cout << fname << setw(2) << lname << setw
(10) << &quot;$&quot; << earnings(hrwage, hrs)
<< setw(5) << &quot;$&quot; << yrEarnings
(earnings(hrwage, hrs), prEarnings)
<< setw(5) << &quot;$&quot; << FICAtax(earnings
(hrwage, hrs), yrEarnings(earnings
(hrwage, hrs), prEarnings), prEarnings)
<< setw(5) << &quot;$&quot; << wkIncome(earnings
(hrwage, hrs), exempt)
<< setw(5) << &quot;$&quot; << marriedTax
(status, wkIncome(earnings(hrwage,
hrs), exempt))
<< setw(5) << &quot;$&quot; << 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);
}
 
Code:
// Look Ma! Only one return statement!
double allfncs(....){
	double dret = 0.0;
	if( ....)
		dret = a + b * d;
	else if( ...)
		dret = z - w * x;
	else if( ...)
		dret = foo;
	else
		dret = junk;

	return dret;
}

-pete

 
pete,

i do not get what you are trying to say. Can you explain more? Thanx.
 
double marriedTax (int status, double wkIncome)
{
if (status == 1)
...
// what if status != 1, where is the return statement?
}

the same for

double singleTax (int status, double wkIncome)
{
if (status == 2)
...
// what if status != 2, where is the return statement?
}

It is recomended to have only one return statement in a function as shown by Pete's reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top