Alright you guys im new to c++ and programming and i have this homework assignment that is incomplete at the moment and i dont know where i messed up.

/*Write a program to compute income tax as follows:

First, display the following menu and ask the user to select his or her filing status:

1. Single

2. Married filing separately

3. Married filing jointly

4. Head of household

For Single status, apply a deduction of $2000, for #2 $1700, for #3, $2300 and Head of household $2700.
Add to the deduction amount, $150 for each dependent up to a maximum of 4 dependents if single, 
$125 for each dependent up to a maximum of 4 for Married filing separately, $175 for each dependent, 
up to a maximum of 5, if married filing jointly, or head of household. 
Add also 15% of any uncovered (out-of-pocket) medical expenses for singles and married filing individually, 
and 20% for the other two.  Likewise add 20% of any college expenses to first and second and 25% for the other two, 
as well as 20% of charitable contributions for all four.

Then, get user's income and compute the taxable income by subtracting the deduction from his or her income. 
Anyone with a taxable income of less than $8,000 pays no taxes. 
For the rest, the first $15,000 of the income has a tax rate of 10%, the next $25,000 gets taxed at 15%, 
the next $30,000 at 20%, the next $30,000 at 25% and anything above $100,000 at 30%.  
So, for example, someone who had taxable income of $125,000, her first $15,000 gets taxed at 10% ($1,500), 
plus 15% of $25,000 ($3,750), plus 20% of $30,000 ($6,000), plus 25% of $30,000 ($7,500) and the remaining $25,000 at 30% ($7,500)
for a total tax amount of $26,250.  For someone with income of $13,000, the tax is 10% of that or $1,300.  
For someone who made $7,999.99 it would be 0, but for someone who made $8,000, it's $800. 
For someone who made $30,000, it would be 10% of $15,000 or $1,500 plus 15% of the remaining $15,000 or $2,250 making it $3,750, 
and so on.

Next, ask for the amount of taxes already paid and subtract from tax due.
If the difference is positive, display the amount due and the address where the check should be sent to
(Franchise Tax Board, Fresno, CA).  Otherwise, if the amount of tax is negative, 
display the refund amount and ask and read the address where the tax refund should be sent to. 
If the difference is 0, tell the user he or she owes nothing and will be getting nothing.*/

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int filing, dependents, income;
    double med1 = .15, med2 = .2, col1 = .2, col2 = .25, charity= .2, paidtax1, paidtax2, paidtax3, paidtax4, paidtax5,
        deduction, leftover, taxrate1, taxrate2, taxrate3, taxrate4, taxrate5, amount1, amount2, amount3, amount4, amount5;

    cout << "\nEnter filing status:\n"
         << "\n1. Single\n"
         <<   "\n2. Married filing separately\n"
         << "\n3. Married filing jointly\n"
         << "\n4. Head of household\n"
         << "\nEnter your selection\n";
    cin >> filing;

    cout << "\nEnter income amount:\n ";
    cin >> income;

    cout << "\nEnter number of dependents: \n"
         << "\n0. None\n"
         << "\n1. One\n"
         << "\n2. Two\n"
         << "\n3. Three\n"
         << "\n4. Four\n"
         << "\n5. Five\n"
         << "\nEnter number of dependents: ";
    cin >> dependents;



    if (filing == 1)
    {
        deduction  =  income - 2000 - ((income * med1)+ (income * col1)+ ( income * charity)); 
        if (dependents == 0)
        {
            cout << income - deduction << endl;
        }
        else if( dependents == 1)
        {
            cout << income - deduction -  150 << endl;
        }
        else if( dependents == 2)
        {
            cout << income - deduction - 300 << endl;
        }
        else if( dependents == 3)
        {
            cout << income -  deduction - 450 << endl;
        }
        else if( dependents == 4)
        {
            cout << income-  deduction - 600 << endl;
        }
        else
        {
            cout << "\nInvalid entry\n";
        }
    }
    else if( filing ==2)
    {
        deduction = income - 1700 - ((income * med1)+ (income * col1)+ ( income * charity));
        if (dependents == 0)
        {
            cout << income -  deduction << endl;
        }
        else if( dependents == 1)
        {
            cout << income - deduction -  125 << endl;
        }
        else if( dependents == 2)
        {
            cout << income - deduction - 250 << endl;
        }
        else if( dependents == 3)
        {
            cout << income - deduction - 375 << endl;
        }
        else if( dependents == 4)
        {
            cout << income - deduction - 500 << endl;
        }
        else
        {
            cout << "\nInvalid entry\n";
        }
    }
    else if(filing == 3)
    {
        deduction = income - 2300 - ((income * med2) + (income * col2) + (income * charity));
        if (dependents == 0)
        {
            cout << income - deduction << endl;
        }
        else if( dependents == 1)
        {
            cout << income - deduction -  175 << endl;
        }
        else if( dependents == 2)
        {
            cout << income - deduction - 350 << endl;
        }
        else if( dependents == 3)
        {
            cout << income - deduction - 525 << endl;
        }
        else if( dependents == 4)
        {
            cout << income - deduction - 700 << endl;
        }
        else if( dependents == 5)
        {
            cout << income - deduction - 875 << endl;
        }
    }
    else if(filing == 4)
    {
        deduction = income - 2700 - ((income * med2) + (income * col2) + (income * charity));
        if (dependents == 0)
        {
            cout << income-  deduction << endl;
        }
        else if( dependents == 1)
        {
            cout << deduction -  175 << endl;
        }
        else if( dependents == 2)
        {
            cout << income - deduction - 350 << endl;
        }
        else if( dependents == 3)
        {
            cout << income - deduction - 525 << endl;
        }
        else if( dependents == 4)
        {
            cout << income - deduction - 700 << endl;
        }
        else if( dependents == 5)
        {
            cout << income - deduction - 875 << endl;
        }
    }

    else 
        cout << "\nInvalid Entry\n";


    leftover = income - deduction;
    taxrate1 = income -  (leftover * .10);
    taxrate2 = income -  (leftover * .15 + taxrate1);
    taxrate3 = income -  (leftover * .20 + taxrate2 + taxrate1);
    taxrate4 = income -  (leftover * .25 + taxrate3 + taxrate2 + taxrate1);
    taxrate5 = income -  (leftover * .30 + taxrate4 + taxrate3 + taxrate2 + taxrate1);
    amount1 = income - taxrate1;
    amount2 = income - taxrate2;
    amount3 = income - taxrate3;
    amount4 = income - taxrate4;
    amount5 = income - taxrate5;


    if (leftover == 15000 && leftover >= 8000)
    {
        cout << "\nThis is your tax rate = " << taxrate1 << endl;
        cout << amount1 << endl;
    }
    else if (leftover == 40000 )
    {   
        cout << "\nThis is your tax rate = " << taxrate2 << endl;
        cout << amount2 << endl;
    }
    else if ( leftover == 70000 )
    {
        cout << "\nThis is your tax rate = " << taxrate3 << endl;
        cout << amount3 << endl;
    }
    else if ( leftover == 100000 )
    {
        cout << "\nThis is your taxrate = " << taxrate4 << endl;
        cout << amount4 << endl;
    }
    else 
    {
        cout << "\nThis is your taxrate = " << taxrate5 << endl;
        cout << amount5 << endl;
    }



    paidtax1 = taxrate1 - amount1;
    paidtax2 = taxrate2 - amount2;
    paidtax3 = taxrate3 - amount3;
    paidtax4 = taxrate4 - amount4;
    paidtax5 = taxrate5 - amount5;

    if (paidtax1 > 0 || paidtax2 > 0 || paidtax3 > 0 || paidtax4 > 0 || paidtax5 > 0)

        cout << "\nPlease send your check to Franchise Tax Board, Fresno, CA.\n " << endl;
    else if (paidtax1 < 0 || paidtax2 < 0 || paidtax3 < 0 || paidtax4 < 0 || paidtax5 < 0)
        cout << "\nPlease send your check to Franchise Tax Board, Fresno, CA.\n " << endl;
    else
        cout << "\nNo taxes are owed, no money is refunded\n" << endl;


    system("pause");
    return 0;
}

Dani AI

Generated

posted a good-faith first attempt; ’s question about whether it’s a compile/link or logic problem is on point — this is mainly logic and data-model errors rather than syntax. The biggest issues: the program treats deduction as “income minus things” (e.g. deduction = income - 2000 - (income * med1)) instead of computing a deduction amount to subtract from income; it applies percentage rates to income rather than to the user-entered medical/college/charity amounts; it never asks for those expense amounts or for taxes already paid/refund address; dependents logic is repetitive and caps are not enforced consistently; money is stored in int instead of double; and the tax-bracket logic uses equality tests like leftover == 15000 instead of range checks and builds confusing intermediate variables (taxrate1..5, amount1..5) that don’t implement progressive taxation.

Fix approach (concise):

  • Read these inputs: filing status, income (double), number of dependents, out‑of‑pocket medical, college, charitable contributions, and taxes already paid.
  • Compute deduction as: base deduction (by filing) + dependent allowance (per dependent, capped) + medPctmedical + colPctcollege + 0.20*charity.
  • Taxable = max(0.0, income - deduction). If taxable < 8000 => tax = 0. Otherwise apply progressive brackets to taxable (first 15,000 @10%, next 25,000 @15%, next 30,000 @20%, next 30,000 @25%, remainder @30%).

Small, safe helper examples (not present in the original post):

double computeDeduction(int filing, int deps, double med, double col, double charity) {
    double base=0, depAmt=0, medPct=0, colPct=0;
    int depCap=0;
    if (filing==1) { base=2000; depAmt=150; depCap=4; medPct=0.15; colPct=0.20; }
    else if (filing==2) { base=1700; depAmt=125; depCap=4; medPct=0.15; colPct=0.20; }
    else if (filing==3) { base=2300; depAmt=175; depCap=5; medPct=0.20; colPct=0.25; }
    else { base=2700; depAmt=175; depCap=5; medPct=0.20; colPct=0.25; }
    int validDeps = std::min(deps, depCap);
    return base + validDeps*depAmt + med*medPct + col*colPct + charity*0.20;
}
double calculateTax(double taxable) {
    if (taxable < 8000.0) return 0.0;
    const double brackets[] = {15000, 25000, 30000, 30000};
    const double rates[] = {0.10,0.15,0.20,0.25,0.30};
    double rem = taxable, tax=0;
    for (int i=0;i<4 && rem>0;i++) {
        double part = std::min(rem, brackets[i]);
        tax += part * rates[i];
        rem -= part;
    }
    if (rem>0) tax += rem * rates[4];
    return tax;
}

Extra notes: use double for money and print with std::fixed<<std::setprecision(2), validate filing/dependent inputs (enforce caps), test with the assignment examples (taxable 125000 => 26250, taxable 30000 => 3750, taxable 13000 => 1300, taxable 7999.99 => 0). Remove unused variables, avoid system("pause"), and keep the I/O sequence clear so refund/address logic is straightforward.

What seems to be the problem officer?
Compilation? Linking? Logic?
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.