0

Good day everyone, Our class has not yet learned about loops, and we have only learned If statements. Professor has assigned a tax calc, but from what I have been reading online is hard for me to understand as I am very novice at programming. I am having trouble getting my numbers to come out in a dollar format, ex: 50000 = $50,000 Any and all tips are appreciated even if it doesn't have to do with the subject. Here is what I have written so far:

#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main()
{
    int iNCOME;


    cout << "Good day Sir/Madam, we noticed your filing status is: Single.For tax purposes, what is your yearly income?";
    cin >> iNCOME;
    cout << " You entered: $" << iNCOME << endl;

       if (iNCOME <= 9325)
        {
         cout << "Your income puts you in the 10% Tax Bracket" << endl << "Your taxes are: $" << iNCOME * 0.1;
        }
        else if ((iNCOME >= 9326) && (iNCOME <= 37950))
        {
         cout << "Your income puts you in the 15% Tax Bracket" << endl << "Your taxes are: $" << iNCOME * 0.15;
        }
        else if ((iNCOME >= 37951) && (iNCOME <= 91900))
        {
         cout << "Your income puts you in the 25% Tax Bracket" << endl << "Your taxes are: $" << iNCOME * 0.25;
        }
        else if ((iNCOME >= 91901) && (iNCOME <= 191650))
        {
         cout << "Your income puts you in the 28% Tax Bracket" << endl << "Your taxes are: $" << iNCOME * 0.28;
        }
        else if ((iNCOME >= 191651) && (iNCOME <= 416700))
        {
         cout << "Your income puts you in the 33% Tax Bracket" << endl << "Your taxes are: $" << iNCOME * 0.33;
        }
        else if ((iNCOME >= 416701) && (iNCOME <= 418400))
        {
         cout << "Your income puts you in the 35% Tax Bracket" << endl << "Your taxes are: $" << iNCOME * 0.35;
        }
        else if (iNCOME >= 418401)
        {
         cout << "Your income puts you in the 39.60% Tax Bracket" << endl << "Your taxes are: $" << iNCOME * 0.396;
        }
        return 0;
    }
  • [c++: Format number with commas?](//stackoverflow.com/q/7276826) – 001 Feb 12 '18 at 17:05
  • Since these are apparently the US tax brackets, your calculation is incorrect, you are not counting the taxes for the lower brackets. That is, you need to total the taxes accumulating from each bracket as you progress to the next one. The $418401 bracket, for example, does not get taxed at 39.6% on the income below $418401. – Nick Feb 12 '18 at 17:13
  • I suspect your professor is using the classic, time-honored tactic of getting you to write a bunch of repetitive code to get those commas in there, then the next lesson will be about loops, then your next assignment will be to improve your current project with loops. – Brandon McKenzie Feb 12 '18 at 17:14

0 Answers0