Hi guys,

I'm working on this problem I've been struggling with for a while now. I'm still confused about parameters and I'm getting all these error messages, saying that a lot of my variables are undefined. I'm sorry, I know this probably looks like a mess right now, but if anyone could help me out as to what I need to change around to get this working, I would be so appreciative.

I'm also not sure if I need the prototypes?

The assignment is in the comments at the top:

// Write a program that can be used to calculate the federal tax. The tax calculated as follows:
// For single people, the standard exemption is \$4000; for married people, the standard exemption
// is \$7000. A person can also put up to 6% of his or her gross standard income in a pension plan.
// The tax rates are as follows: If the taxable income is
// 1) Between \$0 and \$15000, the tax rate is 15%
// 2)between \$15001 and \$40000, the tax is \$2250 plus 25% of the taxable income over \$15000
// 3)Over \$40,000, the tax is \$8460 plus 35% of the taxable income over \$40000
// Prompt the user to enter the following information:
// 4)Martial status
// 5)If the marital status is "married", ask for the number of children under the age of 14
// 6)Gross salary(if the martial status is "married" and both spouses have income, enter the combined salary.)
// 7) Percentage of gross income contributed to a pension fund.

//The program must consist of at least the following functions:
//a) function getData: this function asks the user to enter the relevant data.
//b) function taxAmount: this function computes and returns the tax owned.

//To calculate the taxable income, subtract the sum of the standard exemption, the amount contributed
//to a pension plan, and the personal exemption, which is \$1500 per person.

``````#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

void getData(char marital, int numChild, int& exempt, int& noOfPeople, double& groSalary, double& penAmt);
double taxAmount(double taxIncome, int perExempt, double taxRate);

int main()

{
double groSalary;  //variable for gross salary
double penAmt;     //variable for percent contributed to pension plan
int exempt;        //variable for standard exemption
int noOfPeople;    //variable for number of people

double taxIncome;   //variable for taxable income
double taxRate;     //variable for federal tax amount owed

getData(char marital, int numChild, int& exempt, int& noOfPeople, double& groSalary, double& penAmt);
double taxAmount(double, int, double);

cout << "Your federal tax owed is: " << taxRate << endl;

return 0;
}

void getData(char marital, int numChild, int& exempt, int& noOfPeople, double& groSalary, double& penAmt)
{

char marital;      //variable for marital status
int numChild;      //variable for the number of children under 14

cout << fixed << showpoint;
cout << setprecision(2);

cout << "Enter your marital status: 'M' for Married or 'S' for Single: ";
cin >> marital;
cout << endl;

if (marital == 'M' || marital == 'm')
{

cout << "Enter number of children under the age of 14 years: ";
cout <<endl;
cin >> numChild;
exempt = 7000;
noOfPeople = 2 + numChild;
}
else if (marital == 'S' || marital == 's')
{
exempt = 4000;
numChild = 0;
noOfPeople = 1;
}

cout << "Enter gross salary. (Enter combined salary for both spouses";
cout << "if married): ";
cout << endl;
cin >> groSalary;

cout << "Enter the percentage of your gross income which you have";
cout << " contributed to a pension fund (Only enter the amount if 6%";
cout << " or less of your combined gross income: ";
cout << endl;
cin >> penAmt;

if (penAmt > 6)
{
cout << "You may only enter a percentage which is greater or equal";
cout << " to 6.  Enter the percentage of your gross income which you have";
cout << " contributed to a pension fund.  (Only enter the amount if 6%";
cout << " or less of your combined gross income: ";
cout << endl;
cin >> penAmt;
}

}

double taxAmount(double taxRate, int perExempt, int noOfPeople, double taxRate)
{
double taxRate;  //variable to store taxRate
double taxAmt;   //variable to store total tax amount
int perExempt      //variable for personal Exemptions

taxRate = 0;

perExempt = (noOfPeople * 1500) + exempt;
taxIncome = groSalary - (groSalary * (penAmt * .01)) - perExempt);

if (taxIncome <= 15000)
{taxRate = .15 * taxIncome;
}
else if (taxIncome > 15000 && taxIncome <= 40000)
{taxRate = ((taxIncome - 15000) * .25) + 2250;}
else{
taxRate = ((taxIncome - 40000) * .35) + 8460;
}

return taxRate;

}``````

## All 3 Replies

I didn't read it all but change the line in main to:

``getData(marital, numChild, exempt, noOfPeople, groSalary, penAmt);``

Don't put the data-types in the function calls

edit: and you re-declare alot of stuff......

A parameter is a temporary variable created by your routine. For example:

``````void bigger_than_five( int number )
{
result = (number > 5);
}``````

In this example, number is the parameter (variable).

``````int main()
{
if (bigger_than_five( 42 )) std::cout << "42 is bigger than 5\n";
else std::cout << "hmm... 42 is not bigger than 5 !\n";
}``````

In this example, 42 is the argument or value we give to the variable 'number'.

The only place that the variable number exists is inside the function bigger_than_five(). Hence, the following is an error:

``````int main()
{
number = 42;  // error, 'number' doesn't exist!
if (bigger_than_five( number )) std::cout << "blah blah blah\n";
}``````

I hope this helps.

 Yoinks! I'm slow...

Thanks guys,

I think that helped.

:)

Much appreciated.

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.