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 ;
}

This program works unless I input 's' for marital status. Does anyone see my logic error?

You've been here long enough to know that a question like that is worthless here! What the **** does it do wrong? Other than asking for "Marital Satus" ;)

Hm... well it's supposed to determine the taxes due according to certain circumstances. does that help?


i put in single, 14999, and .01 into pention and should get $1252.35 due, but instead i get 1402.35

Ok, nevermind. I got it working, it was actually always working. It was just a human calculation error on my behalf. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.