Else If question

My code is computing taxes. The user inputs how they are filing and their taxable income. I am trying to display "Error: Invalid income" if the income entered is less than 0. Can someone please take a look at this and help me? Thanks



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
#include <iostream>
using namespace std;

int main()
{
	//prompt the user to enter filling status
	cout << "Enter the filing status\n"
		<< "(0-single filer, 1-married jointly,\n"
		<< "2-married seperatly, 3-head of household): ";
	int status;
	cin >> status;

	// Prompt the user to enter taxable income
	cout << "Enter the taxable income: ";
	double income;
		cin >> income;

	// Compute Tax
	double tax = 0;


	if ( status == 0)
	{
		//compute tax for single filer
		if (income <= 6000)
			tax = income * 0.10;
		else if (income <= 27950)
			tax = 6000 * 0.10 + (income - 6000) * 0.15;
		else if (income <= 67700)
			tax = 6000 * 0.10 + (27950 - 6000) * 0.15 + (income - 27950) * 0.27;
		else if (income <= 141250)
			tax = 6000 * 0.10 + (27950 - 6000) * 0.15 + (67700 - 27950) * 0.27 + (income - 67700 * 0.30);
		else if (income <= 307050)
			tax = 6000 * 0.10 + (27950 - 6000) * 0.15 + (67700 - 27950) * 0.27 + (141250 - 67700) * 0.30 + (income - 141250) * 0.35;
		else
			tax = 6000 * 0.10 + (27950 - 6000) * 0.15 + (67700 - 27950) * 0.27 + (141250 - 67700) * 0.30 + (307050 - 141250) * 0.35 + (income - 307050) * 0.386;
	}
	else if (status == 1)
	{



	}
	else if (status == 2)
	{


	}
	else if (status == 3)
	{



	}
	else
	{
		cout << "Error: invalid filing status ";
		return 0;
	}

	//Display results
	cout << "Tax is " << static_cast<int>(tax * 100) / 100.0 << endl;

	return 0;
}
if (income < 0) std::cout << "Error: Invalid income";
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if ( status == 0)
	{
		//compute tax for single filer
		if (income < 0) std::cout << "Error: Invalid income "; 
		else if (income <= 6000)
			tax = income * 0.10;
		else if (income <= 27950)
			tax = 6000 * 0.10 + (income - 6000) * 0.15;
		else if (income <= 67700)
			tax = 6000 * 0.10 + (27950 - 6000) * 0.15 + (income - 27950) * 0.27;
		else if (income <= 141250)
			tax = 6000 * 0.10 + (27950 - 6000) * 0.15 + (67700 - 27950) * 0.27 + (income - 67700 * 0.30);
		else if (income <= 307050)
			tax = 6000 * 0.10 + (27950 - 6000) * 0.15 + (67700 - 27950) * 0.27 + (141250 - 67700) * 0.30 + (income - 141250) * 0.35;
		else
			tax = 6000 * 0.10 + (27950 - 6000) * 0.15 + (67700 - 27950) * 0.27 + (141250 - 67700) * 0.30 + (307050 - 141250) * 0.35 + (income - 307050) * 0.386;
	}


When this outputs it reads something like this...


Error: Invalid income Tax is 0


How do I get this to read stictley Error:Invalid income
Don't display the results near the end of your code where you have cout << "Tax is "...
You can use the if stament here too.
Last edited on
Topic archived. No new replies allowed.