I am trying to modify a tax program so that I only have one line that start with the variable "tax = ...".

The original statements are commented out so that you may see what the original program looked like. What I don't know how to do is to put the calculations into one line so that the output is the tax.

Please help!

#include <iostream>
#include <string>

using namespace std;

int main()
{
	const double SINGLE_LEVEL1 = 21450.00;
	const double SINGLE_LEVEL2 = 51900.00;

	const double SINGLE_TAX1 = 3217.50;
	const double SINGLE_TAX2 = 11743.50;

	const double MARRIED_LEVEL1 = 35800.00;
	const double MARRIED_LEVEL2 = 86500.00;

	const double MARRIED_TAX1 = 5370.00;
	const double MARRIED_TAX2 = 19566.00;

	const double RATE1 = 0.15;
	const double RATE2 = 0.28;
	const double RATE3 = 0.31;

	double income;
	double cutoff15;
	double cutoff28;
	double cutoff31;
	double tax;
	
	
	string marital_status;

	cout << "Please enter your income: ";
	cin >> income;
	
	cout << "Please enter s for single, m for married: ""\n";
	cin >> marital_status;

	if (marital_status == "s")
	{
		if (income <= SINGLE_LEVEL1)
			cutoff15 = RATE1 * income; //tax = RATE1 * income;
        else if (income <= SINGLE_LEVEL2)
            cutoff28 = SINGLE_TAX1 + RATE2 * (income - SINGLE_LEVEL1);//tax = SINGLE_TAX1 + RATE2 * (income - SINGLE_LEVEL1);
        else
            cutoff31 = SINGLE_TAX2 + RATE3 * (income - SINGLE_LEVEL2);//tax = SINGLE_TAX2 + RATE3 * (income - SINGLE_LEVEL2);
	}
	if (marital_status == "m")
	{
		if (income <= MARRIED_LEVEL1)	
			cutoff15 = RATE1 * income;//tax = RATE1 * income;
        else if (income <= MARRIED_LEVEL2)
            cutoff28 = MARRIED_TAX1 + RATE2 * (income - MARRIED_LEVEL1);//tax = MARRIED_TAX1 + RATE2 * (income - MARRIED_LEVEL1);
        else
            cutoff31 = MARRIED_TAX2 + RATE3 * (income - MARRIED_LEVEL2);//tax = MARRIED_TAX2 + RATE3 * (income - MARRIED_LEVEL2);
	}	
	
	
	//cout << "The tax is $" << tax << "\n";
	return 0;
}

What are all of those cutoff* variables? Why wouldn't you just assign the calculations to 'tax' as was done originally?

I have to modify the program so that there is only one use of "tax" at the end of the program. I used the cutoff variable, basically, to replace the 'tax' and then make calculations and use tax at the end of the program. In the end, the modified program must do the same thing that the original did but without the six "tax" equations.

Is this for a course assignment? I'm still not sure what you are trying to accomplish? The conditionals inside which you compute the 'tax' seem like a reasonable approach.

Yes, this is for an assignment. I am just lost and my mind has been spinning. I've thought of using the && operator and putting:

if (income <= SINGLE_LEVEL1 && income <= MARRIED_LEVEL1)
		cutoff15 = RATE1 * income

so that I could use cutoff15 in the 'tax' formula at the end but I don't think that will work.

Basically, I have to edit original program, set variables cutoff15 and cutoff28 that depend on marital status. Then at the end of the program, have a single formula that computes the tax, depending on the incomes and the cutoffs and then I have to verify that my results are identical to that of the original program.

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.