Expected Primary Expression Error | Assignment of Double Function

I am working on this problem for a class, and I am running into a lot of errors. I spent a good deal of time trying to troubleshoot/de-bug my code, but have been unable to get rid of all of the errors. I would love a few tips or ways to fix the various errors that are popping up. Here is the problem:
"Write a program that can be used to calculate the federal tax. The tax is calculated as follows: For single people, the standard exemption is $4,000; for married people, the standard exemption is $7,000. A person can also put up to 6% of his or her gross income in a pension plan. The tax rates are as follows:

If the taxable income is:

Between $0 and $15,000, the tax rate is 15%.
Between $15,001 and $40,000, the tax is $2,250 plus 25% of the taxable income over $15,000.
Over $40,000, the tax is $8,460 plus 35% of the taxable income over $40,000.
Prompt the user to enter the following information:

Marital status
If the marital status is ‘‘married,’’ ask for the number of children under the age of 14
Gross salary (If the marital status is ‘‘married’’ and both spouses have income, enter the combined salary.)
Percentage of gross income contributed to a pension fund
Your program must consist of at least the following functions:

Function getData: This function asks the user to enter the relevant data.
Function taxAmount: This function computes and returns the tax owed.
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 $1,500 per person. (Note that if a married couple has two children under the age of 14, then the personal exemption is $1,500 * 4 = $6,000.)"

And here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream> 
#include <iomanip>

using namespace std;

// program constants


// declare getData and taxAmount functions
void getData(char& mStatus, int& nOfChildren, double& salary, double& pContribPension);
double taxAmount(char mStatus, int nOfChildren, double salary, double pContribPension);

int main()
{
    char maritalStatus; 
    int numberOfChildren; 
    double grossSalary;
    double pContributedToPension;

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

    // call getData
   getData(char mStatus, int nOfChildren, double salary, double pContribPension);
    // output tax amount using taxAmount
   taxAmount(char mStatus, int nOfChildren, double salary, double pContribPension);

    return 0;
}

void getData(char& mStatus, int& nOfChildren, double& salary,
             double& pContribPension)
{
    // write your getData function here
   
   cout << "Are you currently married?" << endl;
   cin >> mStatus;
   if (mStatus='m'){
       cout << endl << "How many children under the age of 14 do you have?" << endl;
       cin >> nOfChildren; 
       cout << endl << "What is your combined salary?" << endl;
       cin >> salary;
       cout << endl; 
   }
   else { 
     cout << endl << "What is your gross salary?" << endl;
     cin >> salary;
   cout << endl << "What percentage of your gross income goes into a pension fund?" << endl;
   cin >> pContribPension;
   cout << endl;
    }
}
double taxAmount(char mStatus, int nOfChildren, double salary,
                 double pContribPension)
{
     //write your taxAmount function here
   double taxIncome;
   double taxRate;
   if (mStatus='m'){
       taxIncome=salary-7000;
   }
   else {
       taxIncome=salary-4000;
   taxIncome=taxIncome-(pContribPension*salary)-(1500);
   }
   if (mStatus='m')
       taxIncome=taxIncome-1500;
   if (nOfChildren=2)
       taxIncome=taxIncome-(6000-1500);
   cout << "Taxable income is $" << taxIncome << "." << endl;
   
   if (taxIncome<=15000)
       taxRate=.15;
   if (taxIncome<=40000 && taxIncome>=15001)
       taxRate=.25;
   if (taxIncome>40000)
       taxRate=.35;
    
   if (taxIncome<=15000)
       taxAmount=taxIncome*taxRate;
   if (taxIncome<=40000 && taxIncome>=15001)
       taxAmount=((taxIncome-15000)*taxRate)+2250;
   if (taxIncome>40000)
       taxAmount=((taxIncome-40000)*taxRate)+8460;
    return taxAmount;
   
}


Thanks for any and all help!
Last edited on
Get rid of all the char, int, double stuff in the calls. They don't belong there. You also have to pass the variables from main, not the names form the function definitions.

Also remember that comparison is == (two equals signs). You've written it as just one everywhere.

Don't assign to a function name, taxAmount = ....
Declare a new local variable with a differnent name and use that for the return value.
Last edited on
Line 24 & 26: when calling a function, you don't give the parameter type, just the parameter. You give the type only when defining or declaring the function. So, for example, line 24 should be
getData(mStatus, nOfChildren, salary, pContribPension);

Line 25: The comment indicates that taxAmount will output the tax, but it fact it doesn't.
I'd store the value returned from taxAmount in a variable and output the variable.

The parameters you pass must be existing variables. So rename the variables at lines 15-18 to match the ones passed at lines 24-26

Line 36: This is yes/no question. Maybe change it to "please enter your marital status?"

Line 38: C++ uses == for comparison, not =.

Lines 48-50: You're prompting for retirement contribution only for single people. Move the brace that closes the "else" to above here.

If a person is single, you should explicitly set nOfChildren to zero.

Line 80: At tpb said, you need a variable to assign the return value to. I always use "result" for consistency.

Line 64: single people have pensions too.

Lines 68-69: You're computing the personal exemption for children wrong. Hint: What is the exemption for 4 children? What is it for 7 children?
Thank you guys so much! I also had a different error in my original code with the logic behind it...

Line 64 was calculating the taxable income without using an actual percent, and would just use the whole number that was input by a user. Also, I had

Thank you again, and I am glad to have been able to figure this out with your help!
Topic archived. No new replies allowed.