Thread: Help with Federal taxes Excercise

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    10

    Help with Federal taxes Excercise

    My assignment is to write a program that can calculate federal taxes. Single people exemption is 4000 and married is 7000. Can also add 6% of income to pension plan. Tax rates are: Between 0 - 15000 rate is 15%, Between 15001 - 40000 tax is 2250 and rate of 25% over 15000.
    Over 40000 tax is 8460 and rate of 35% over 40000.
    Prompt user for Marital Status, if married ask for any children under 14, Gross Salary and Percentage of income contributed to pension.

    must use function getData and taxAmount. Personal Exemption is Self plus children at 1500 per person.

    Here is my code:

    Code:
    
    
    #include <iostream>
    #include <iomanip>
    
    
    using namespace std;
    
    
    void getdata();
    double taxAmount( double status1, double GrossAmount, double pension, double kids);
    
    
    int main ()
    {
        char S = 0;
        double G = 0;
        double P = 0;
        double K = 0;
        
    
    
    
    
        getdata();
        
    
    
        return 0;
    
    
    }
    
    
    void getdata()
    {
        
        char status;
        double GAmount;
        char pension;
        double child;
        char filing;
        double kid;
        double pension1;
    
    
        cout << "Enter Marital Status S/s for Singele: \n";
        cout << "or M/m for Married: " << endl;
        cin >> status;
    
    
        switch (status)
        {
        case 'S':
        case 's':
            cout << "Enter Gross Salary Amount: ";
            cin >> GAmount;
            kid = 0;
    
    
            cout << "Take out up to 6% into Pension Plan? \n";
            cout << "Input Y/y for Yes or N/n for No: ";
            cin >> pension;
            if (pension == 'Y' || pension == 'y')
                cout << "How Much would you like to contribute (enter as decimal: " << endl;
                cin >> pension1;
            if (pension == 'N' || pension == 'n')
                pension1 = 0;
    
    
            taxAmount(static_cast<char>(status),GAmount,pension1,kid);
            break;
        case 'M':
        case 'm':
            cout << "Will you be filing seperate N/n for No or Y/y for Yes: " << endl;
            cin >> filing;
            if (filing == 'Y' || filing == 'y')
            cout << "Enter Combined Gross Salary Amount: " << endl;
            cin >> GAmount;
            cout << "Take out 6% to put into Pension Plan? \n";
            cout << "Input Y/y for Yes or N/n for No: " << endl;
            cin >> pension;
            if (pension == 'Y' || pension == 'y')
                cout << "How Much would you like to contribute (enter as decimal: " << endl;
                cin >> pension1;
            if (pension == 'N' || pension == 'n')
                pension1 = 0;
            cout << "Enter how many children under age of 14?" << endl;
            cin >> child;
            kid = child + 2;
            taxAmount(static_cast<char>(status),GAmount,pension1,kid);
            if (filing == 'N' || filing == 'n')
                cout << "Enter Your Gross Salary Amount: " << endl;
            cin >> GAmount;
            cout << "Take out 6% to put into Pension Plan? \n";
            cout << "Input Y/y for Yes or N/n for No: " << endl;
            cin >> pension;
            if (pension == 'Y' || pension == 'y')
                cout << "How Much would you like to contribute (enter as decimal: " << endl;
                cin >> pension1;
            if (pension == 'N' || pension == 'n')
                pension1 = 0;
            cout << "Enter how many children under age of 14?" << endl;
            cin >> child;
            kid = child + 1;
            taxAmount(static_cast<char>(status),GAmount,pension1,kid);
            break;
        }
    
    
    }    
    double taxAmount(char status1, double GrossAmount, double pension, double kids)
    {
        double rate1 = .15;
        double rate2 = .25;
        double Mrate2 = 2250;
        double rate3 = .35;
        double Mrate3 = 8460;
        double Tax;
        double NewPen;
        double calcKids;
        double Taxed;
        double SinExem = 4000;
        double MarriedExem = 7000;
    calcKids = (kids * 1500);
        switch (status1)
        {
            case 'S':
            case 's':
        if (GrossAmount <= 15000)
            NewPen = (GrossAmount * pension);
            Taxed = GrossAmount * rate1;
            Tax = (GrossAmount + SinExem) - (Taxed + calcKids + NewPen);
            cout << "Gross Amount: " << GrossAmount << endl;
            cout << "Exemption: " << SinExem << endl;
            cout << "Tax: "  << Taxed << endl;
            cout << "Pension Contributed: " << NewPen << endl;
            cout << "Total Owed: " << Tax << endl;
        if(GrossAmount >= 15001 && GrossAmount <= 40000)
            NewPen = (GrossAmount * pension);
            Taxed = ((GrossAmount - 15000) * rate2) + Mrate2;
            Tax = (GrossAmount + SinExem) - (Taxed + calcKids + NewPen);
            cout << "Gross Amount: " << GrossAmount << endl;
            cout << "Exemption: " << SinExem << endl;
            cout << "Tax: "  << Taxed << endl;
            cout << "Pension Contributed: " << NewPen << endl;
            cout << "Total Owed: " << Tax << endl;
        if(GrossAmount >= 40001)
            NewPen = (GrossAmount * pension);
            Taxed = ((GrossAmount - 40000) * rate3) + Mrate3;
            Tax = (GrossAmount + SinExem) - (Taxed + calcKids + NewPen);
            cout << "Gross Amount: " << GrossAmount << endl;
            cout << "Exemption: " << SinExem << endl;
            cout << "Tax: "  << Taxed << endl;
            cout << "Pension Contributed: " << NewPen << endl;
            cout << "Total Owed: " << Tax << endl;
        break;
            case 'M':
            case 'm':
    if (GrossAmount <= 15000)
            NewPen = (GrossAmount * pension);
            calcKids = (kids * 1500);
            Taxed = GrossAmount * rate1;
            Tax = (GrossAmount + MarriedExem) - (Taxed + calcKids + NewPen);
            cout << "Gross Amount: " << GrossAmount << endl;
            cout << "Exemption: " << MarriedExem << endl;
            cout << "Tax: "  << Taxed << endl;
            cout << "Pension Contributed: " << NewPen << endl;
            cout << "Total Owed: " << Tax << endl;
        if(GrossAmount >= 15001 && GrossAmount <= 40000)
            NewPen = (GrossAmount * pension);
            calcKids = (kids * 1500);
            Taxed = ((GrossAmount - 15000) * rate2) + Mrate2;
            Tax = (GrossAmount + MarriedExem) - (Taxed + calcKids + NewPen);
            cout << "Gross Amount: " << GrossAmount << endl;
            cout << "Exemption: " << MarriedExem << endl;
            cout << "Tax: "  << Taxed << endl;
            cout << "Pension Contributed: " << NewPen << endl;
            cout << "Total Owed: " << Tax << endl;
        if(GrossAmount >= 40001)
            NewPen = (GrossAmount * pension);
            calcKids = (kids * 1500);
            Taxed = ((GrossAmount - 40000) * rate3) + Mrate3;
            Tax = (GrossAmount + MarriedExem) - (Taxed + calcKids + NewPen);
            cout << "Gross Amount: " << GrossAmount << endl;
            cout << "Exemption: " << MarriedExem << endl;
            cout << "Tax: "  << Taxed << endl;
            cout << "Pension Contributed: " << NewPen << endl;
            cout << "Total Owed: " << Tax << endl;
    
    
            break;
        }
        return 0;
    }

    and this is the error I keep getting:

    1>ftax.obj : error LNK2019: unresolved external symbol "double __cdecl taxAmount(double,double,double,double)" (?taxAmount@@YANNNNN@Z) referenced in function "void __cdecl getdata(void)" (?getdata@@YAXXZ)
    1>C:\data\ftax\Debug\ftax.exe : fatal error LNK1120: 1 unresolved externals

    I have no clue what it means and I am in my first course of C++ so am really new to this any help will be appreciated.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    >>double taxAmount( double status1, double GrossAmount, double pension, double kids);
    double taxAmount(char status1, double GrossAmount, double pension, double kids)

    Declaration and definition do not match.
    Also, if statements longer than one line must have braces around it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    char status1 should be bool isMarried

    whenever you find yourself doing repetitive copy/paste, you should refactor your code to eliminate those redundancies.

    consider using an object to logically group information about individuals and tax brackets.

  4. #4
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Simplified tax form:
    How much money did you make last year? Mail it in.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  5. #5
    Registered User
    Join Date
    Mar 2012
    Posts
    10
    I am taking this course through the internet which is basically read chapters do the exercises. I read the chapter on Enum and object types but I do not understand at all that well if you can maybe put it in simple terms for me maybe I can get what it is suppose to be

  6. #6
    Registered User
    Join Date
    Mar 2012
    Posts
    10
    Ok So I restarted my coding so my question is how do I retrieve all the data in my void getdata(); to use in my double taxAmount()? here is my code:

    Code:
    #include <iostream>
    #include <iomanip>
    
    
    using namespace std;
    
    
    enum statusType {Single, Married};
    statusType retrievestatus(char selection);
    bool validstatus(char selection);
    void getdata(char status1);
    double taxAmount();
    
    
    int main ()
    
    
    {
    	char stat;
    
    
    	cout << "What is your Marital Status? \n ";
    	cout << "Enter S/s for Single or M/m for Married:   ";
    	cin >> stat;
    	
    	
    	getdata(stat);
    
    
    
    
    
    
    }
    
    
    void getdata(char status1)
    {
    	double Gsalary;
    	char combined;
    	double CSalary;
    	int kids;
    	char pensionChoice;
    	double pension;
    
    
    	if (status1 == 'S' || status1 == 's')
    	{ 
    		cout << "What is Gross Salary? ";
    		cin >> Gsalary;
    	}
    	if (status1 == 'M' || status1 == 'm')
    	{
    		cout << "Do both spouses earn money? \n   ";
    		cout << "Enter Y/y for Yes or N/n for No: ";
    		cin >> combined;
    	if (combined == 'Y' || combined == 'y')
    	{
    		cout << "Enter combined Salary: ";
    		cin >> CSalary;
    	}
    	else 
    	{
    		cout << "Enter Gross Salary: ";
    		cin >> Gsalary;
    	}
    
    
    	cout << "Enter Number of Kids under 14: ";
    	cin >> kids;
    	}
    
    
    	cout << "Would you like to contribute up to 6% \n ";
    	cout << "to Pension Plan? \n " ;
    	cout << "Enter Y/y for yes or N/n for No: ";
    	cin >> pensionChoice;
    
    
    	if (pensionChoice == 'Y' || pensionChoice == 'y')
    	
    		cout << "Enter percentage amount (in decimals): " ;
    		cin >> pension;
    	
    	if (pension > .06)
    	{
    		cout << "Cannot be higher than 6%. Please Enter percentage amount (in decimals): " ;
    		cin >> pension;
    	}
    	else
    	{
    		pension = 0;
    	}
    
    
    }
    
    
    double taxAmount()
    {
    	double const SinExem = 4000.00;
    	double const MarExem = 7500.00;
    	double const rate1 = 0.15;
    	double const rate2 = 0.25;
    	double const rate3 = 0.35;
    	double const tax1 = 2250.00;
    	double const tax2 = 8460.00;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    		
    
    
    
    
    
    
    
    
    
    
    bool validstatus(char selection)
    {
    	switch (selection)
    	{
    	case 'S':
    	case 's':
    	case 'M':
    	case 'm':
    		return true;
    	default:
    		return false;
    	}
    }
    
    
    statusType retrievestatus(char selection)
    {
        statusType status;
    
    
    	switch (selection)
    	{
    	case 'M':
    	case 'm':
    		status = Married;
    	case 'S':
    	case 's':
    		status = Single;
    
    
    	}
    
    
    	return status;
    }

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Did you forget a brace in TaxAmount?
    As for the question, I suggest you pass variables by reference that GetData can fill, making it available inside TaxAmount.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Program Help - Calculating Federal Tax
    By MetDude21 in forum C Programming
    Replies: 10
    Last Post: 02-18-2011, 12:51 PM
  2. Taxes in the US for freelancers or contractor
    By C_ntua in forum General Discussions
    Replies: 6
    Last Post: 06-28-2010, 05:28 AM
  3. Calculating Taxes
    By Mark_Guy in forum C Programming
    Replies: 8
    Last Post: 10-22-2008, 10:31 AM
  4. what does marriage mean in terms of taxes
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-03-2004, 07:39 PM
  5. Help with Excercise
    By Blanket in forum C++ Programming
    Replies: 6
    Last Post: 03-24-2003, 05:21 PM