This program works unless I input 's' for marital status. Does anyone see my logic error?
#include <iostream>
#include <iomanip>
using namespace std ;
void getData ( int& numChild , double& grossSalary , double& penPay , char& maritalStat ) ;
double taxAmount ( int& numChild , double& grossSalary , double& penPay , char& maritalStat ) ;
int main()
{
int numChild ;
double grossSalary ;
double penPay ;
double taxPay ;
char maritalStat ;
getData ( numChild , grossSalary , penPay , maritalStat ) ;
taxPay = taxAmount ( numChild , grossSalary , penPay , maritalStat ) ;
cout << fixed << showpoint << setprecision(2) ;
if ( taxPay < 0 )
{
cout << "Tax Owed: $0.00" << endl ;
}
else
cout << "Tax Owed: $" << taxPay << endl ;
}
void getData ( int& numChild , double& grossSalary , double& penPay , char& maritalStat )
{
int x ;
cout << "Marital Satus [M/S]: " << flush ;
cin >> maritalStat ;
if ( maritalStat == 'm' || maritalStat == 'M' )
{
for ( x = 0 ; x < 1 ; x++ )
{
cout << "Number of children under the age of 14: " << flush ;
cin >> numChild ;
if ( numChild < 0 )
{
cout << " -- ! INVALID INPUT ! --" << endl ;
x = -1 ;
}
}
}
cout << "Gross Salary --[ if married, enter combined salary ]-- : $" << flush ;
cin >> grossSalary ;
for ( x = 0 ; x < 1 ; x++ )
{
cout << "Percentage of Gross Income Contributed to a Pension Plan [0.00 - 0.06]: " << flush ;
cin >> penPay ;
if ( ( penPay > 0.06 ) || ( penPay < 0 ) )
{
cout << " -- ! INVALID INPUT ! --" << endl ;
x = -1 ;
}
}
}
double taxAmount ( int& numChild , double& grossSalary , double& penPay , char& maritalStat )
{
const double STANDARD_EXEMP = 4000.00 ;
const double MARITAL_EXEMP = 7000.00 ;
const double RATE_TIER_1 = 0.15 ;
const double RATE_TIER_2 = 0.25 ;
const double TAX_TIER_2 = 2250.00 ;
const double RATE_TIER_3 = 0.35 ;
const double TAX_TIER_3 = 8460.00 ;
double taxableIncome ;
double taxPay ;
if ( maritalStat == 'm' || maritalStat == 'M' )
taxableIncome = grossSalary - ( MARITAL_EXEMP + ( grossSalary * penPay ) + ( ( 1500 * ( numChild + 2 ) ) ) ) ;
else
taxableIncome = grossSalary - ( STANDARD_EXEMP + ( ( grossSalary * penPay ) + 1500 ) ) ;
if ( grossSalary < 15000 )
taxPay = taxableIncome * RATE_TIER_1 ;
if ( ( grossSalary > 15000 ) && ( grossSalary < 40000 ) )
taxPay = ( taxableIncome * RATE_TIER_2 ) + TAX_TIER_2 ;
if ( grossSalary > 40000 )
taxPay = ( taxableIncome * RATE_TIER_3 ) + TAX_TIER_3 ;
return taxPay ;
}