Taking a percentage
Jun 29, 2011 at 1:14pm UTC
My code is computing taxes. The user inputs how they are filing and their taxable income. If the user inputs a 1 (married jointly) I need that tax to calculate as 83% of the total tax rate of a singe filer. This will be inputted under the else if ( status == 1) statement. Could someone get me started and show me how to make married jointly output 83% of the tax rate of a single filer? 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;
}
Jun 29, 2011 at 1:28pm UTC
Same calculation as for single filer, with one change at the end.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
else if (status == 1)
{
//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;
cout << "Tax is " << tax * 0.83 << endl;
}
Last edited on Jun 29, 2011 at 1:29pm UTC
Jun 29, 2011 at 1:36pm UTC
could I do an if else statement for my couts? I am on nothing but apple computers till I get off work lol.
something like this
1 2 3 4 5 6 7 8 9
//results
if (income < 0) std::cout << "Error: Invalid income " ;
else if ( status == 0)
cout << "Tax is " << static_cast <int >(tax * 100) / 100.0 << endl;
else if ( status == 1)
cout << "Tax is " << static_cast <int >(tax* 83) / 100.0 << endl;
Last edited on Jun 29, 2011 at 1:36pm UTC
Jun 30, 2011 at 2:07am UTC
Finished 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
#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;
// Display results
if (income < 0) std::cout << "Error: Invalid income " ;
else if (cout << "Tax is " << static_cast <int >(tax * 100) / 100.0 << endl);
}
else if (status == 1)
{
//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;
// Display results
if (income < 0) std::cout << "Error: Invalid income " ;
else if (cout << "Tax is " << tax * 0.83 << endl);
}
else
{
cout << "Error: invalid filing status " ;
return 0;
}
return 0;
}
Jun 30, 2011 at 3:14pm UTC
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 88 89 90 91 92 93 94 95 96 97 98 99
#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)
{
//compute tax for filing jointly
if (income <= 12000)
tax = income * 0.10;
else if (income <= 46700)
tax = 12000 * 0.10 + (income - 12000) * 0.15;
else if (income <= 112850)
tax = 12000 * 0.10 + (46700 - 12000) * 0.15 + (income - 46700) * 0.27;
else if (income <= 171950)
tax = 12000 * 0.10 + (46700 - 12000) * 0.15 + (112850 - 46700) * 0.27 + (income - 112850) * 0.30;
else if (income <= 307050)
tax = 12000 * 0.10 + (46700 - 12000) * 0.15 + (112850 - 46700) * 0.27 + (171950 - 112850) * 0.30 + (income - 171950) * 0.35;
else
tax = 12000 * 0.10 + (46700 - 12000) * 0.15 + (112850 - 46700) * 0.27 + (171950 - 112850) * 0.30 + (307050 - 171950) * 0.35 + (income - 307050) * 0.386;
}
else if ( status == 2)
{
//compute tax for married filing seperatly
if (income <= 6000)
tax = income * 0.10;
else if (income <= 23350)
tax = 6000 * 0.10 + (income - 6000) * 0.15;
else if (income <= 56425)
tax = 6000 * 0.10 + (23350 - 6000) * 0.15 + (income - 23350) * 0.27;
else if (income <= 85975)
tax = 6000 * 0.10 + (23350 - 6000) * 0.15 + (56425 - 23350) * 0.27 + (income - 56425) * 0.30;
else if (income <= 153525)
tax = 6000 * 0.10 + (23350 - 6000) * 0.15 + (56425 - 23350) * 0.27 + (85975 - 56425) * 0.30 + (income - 85975) * 0.35;
else
tax = 6000 * 0.10 + (23350 - 6000) * 0.15 + (56425 - 23350) * 0.27 + (85975 - 56425) * 0.30 + (153525 - 85975) * 0.35 + (income - 153525) * 0.386;
}
else if ( status == 3)
{
//compute tax for head of house
if (income <= 10000)
tax = income * 0.10;
else if (income <= 37450)
tax = 10000 * 0.10 + (income - 10000) * 0.15;
else if (income <= 96700)
tax = 10000 * 0.10 + (37450 - 10000) * 0.15 + (income - 37450) * 0.27;
else if (income <= 156600)
tax = 10000 * 0.10 + (37450 - 10000) * 0.15 + (96700 - 37450) * 0.27 + (income - 96700) * 0.30;
else if (income <= 307050)
tax = 10000 * 0.10 + (37450 - 10000) * 0.15 + (96700 - 37450) * 0.27 + (156600 - 96700) * 0.30 + (income - 156600) * 0.35;
else
tax = 10000 * 0.10 + (37450 - 10000) * 0.15 + (96700 - 37450) * 0.27 + (156600 - 96700) * 0.30 + (307050 - 156600) * 0.35 + (income - 307050) * 0.386;
}
else
{
cout << "Error: invalid filing status " ;
return 0;
}
//Display invalid income or Tax
if (income < 0) std::cout << "Error: Invalid income " ;
else if (cout << "Tax is " << static_cast <int >(tax * 100) / 100.0 << endl);
return 0;
}
Topic archived. No new replies allowed.