Can't understand compiler? I think that's the problem

Hey everyone, I’m back with another project in which I am calculating taxes:sweat:

My code keeps coming up with errors, I think its freaking out because I keep using ‘+’, but I have no idea why? It also keeps saying “married” was not declared in this scope. Here’s my code:

#include <iostream>
#include <string>
#include <cmath>
using namespace std;

const int personalExemption = 1500;
const int mStEx = 7000;
const int singStEx = 4000;

double pensionPlan (double grossSalary, double pensionFund);

int pExemption (string maritalStatus, int children, int personalExemption);

int main() {
    string maritalStatus;
    int children;
    double grossSalary;
    double pensionFund;
    char ch;
    double taxableIncome;
    cout << "Are you single or married?";
    cin >> maritalStatus;
    cout << endl;
    
    if (maritalStatus == married)
    {
        cout << "How many children do you have under"
             << " the age of fourteen?";
        cin >> children;
        cout << endl;
        cout << "Do you and your spouse both have income? If"
             << " so, enter your combined salary: $";
        cin >> grossSalary;
        cout << endl;
    }
    
    cout << "What percentage of your gross income is"
         << " contributed to your pension fund? (Enter a"
         << " percentage.)";
    cin >> pensionFund >> ch;
    cout << endl;
    
    taxableIncome = grossSalary - (mStEx + pensionPlan + pExemption)
    return 0;
}

double pensionPlan (double grossSalary, double pensionFund)
{
    double pensionAmount;
    
    pensionAmount = grossSalary * pensionFund;
    return 0;
}

int pExemption (string maritalStatus, int children, int personalExemption)
{
    int exemption;
    
    if (maritalStatus == married)
        exemption = (2 + children) * personalExemption;
        else
            exemption = personalExemption;
    return 0;
}

Hello, @trinitycribbs.

You’ve declared maritalStatus as a string, so is married a variable with a string value assigned, or is it intended to be a string literal "married". It would appear to be the later.

1 Like

@midlindner Okay so that fixed one problem, can’t believe I missed that:sweat_smile:

2 Likes

I haven’t tried running your code, but I’ve noticed lines such as this one:

pensionPlan and pExemption appear to be methods with required parameters. To get a value from the methods, you’ll have to call them: pensionPlan(argument1, argument2)
Then at the end of the method, instead of return 0; you’ll need to return the value expected. For example:

double pensionPlan (double grossSalary, double pensionFund)
{
    double pensionAmount;
    
    pensionAmount = grossSalary * pensionFund;
    return 0; //return pensionAmount;
//or even more concise: return grossSalary * pensionFund;
//if you used the second option, you could do away with the first 2 lines in this method
}
1 Like

@midlindner omg, that’s the same mistake I made with my last project, I can’t believe I didn’t think of that! also your suggestion for cleaning up pensionPlan is much appreciated

2 Likes