954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Logic error?

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

<pre><code>#include &lt;iostream&gt;
#include &lt;iomanip&gt;

using namespace std ;

void getData ( int&amp; numChild , double&amp; grossSalary , double&amp; penPay , char&amp; maritalStat ) ;
double taxAmount ( int&amp; numChild , double&amp; grossSalary , double&amp; penPay , char&amp; 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 &lt;&lt; fixed &lt;&lt; showpoint &lt;&lt; setprecision(2) ;
    if ( taxPay &lt; 0 )
    {
        cout &lt;&lt; &quot;Tax Owed:  $0.00&quot; &lt;&lt; endl ;
    }
    else
        cout &lt;&lt; &quot;Tax Owed:  $&quot; &lt;&lt; taxPay &lt;&lt; endl ;

}

void getData ( int&amp; numChild , double&amp; grossSalary , double&amp; penPay , char&amp; maritalStat )
{
    int x ;

    cout &lt;&lt; &quot;Marital Satus [M/S]:  &quot; &lt;&lt; flush ;
    cin &gt;&gt; maritalStat ;

    if ( maritalStat == 'm' || maritalStat == 'M' )
    {
        for ( x = 0 ; x &lt; 1 ; x++ )
        {
        cout &lt;&lt; &quot;Number of children under the age of 14:  &quot; &lt;&lt; flush ;
        cin &gt;&gt; numChild ;
        if ( numChild &lt; 0 )
        {
            cout &lt;&lt; &quot; --  ! INVALID INPUT !  --&quot; &lt;&lt; endl ;
            x = -1 ;
        }
        }
    }
    
    cout &lt;&lt; &quot;Gross Salary  --[ if married, enter combined salary ]-- :  $&quot; &lt;&lt; flush ;
    cin &gt;&gt; grossSalary ;

    for ( x = 0 ; x &lt; 1 ; x++ )
    {
    cout &lt;&lt; &quot;Percentage of Gross Income Contributed to a Pension Plan [0.00 - 0.06]:  &quot; &lt;&lt; flush ;
    cin &gt;&gt; penPay ;
    if ( ( penPay &gt; 0.06 ) || ( penPay &lt; 0 ) )
    {
        cout &lt;&lt; &quot; --  ! INVALID INPUT !  --&quot; &lt;&lt; endl ;
        x = -1 ;
    }
    }
}

double taxAmount ( int&amp; numChild , double&amp; grossSalary , double&amp; penPay , char&amp; 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 &lt; 15000 )
        taxPay = taxableIncome * RATE_TIER_1 ;
    if ( ( grossSalary &gt; 15000 ) &amp;&amp; ( grossSalary &lt; 40000 ) )
        taxPay = ( taxableIncome * RATE_TIER_2 ) + TAX_TIER_2 ;
    if ( grossSalary &gt; 40000 )
        taxPay = ( taxableIncome * RATE_TIER_3 ) + TAX_TIER_3 ;

    return taxPay ;
}</code></pre>
Duki
Nearly a Posting Virtuoso
1,475 posts since Jun 2006
Reputation Points: 817
Solved Threads: 32
 
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 "MaritalSatus" ;)

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

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

Duki
Nearly a Posting Virtuoso
1,475 posts since Jun 2006
Reputation Points: 817
Solved Threads: 32
 

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

Duki
Nearly a Posting Virtuoso
1,475 posts since Jun 2006
Reputation Points: 817
Solved Threads: 32
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You