I am new to the forum and also to C++ programming. One of my projects is that I have to write a program that calculates taxes for different brackets. I have the following brackets:
0 to 4999-----pay no taxes
5000 to 14,999---pays 10%
15000 to 34999---pays 15%
and from 35,000---pays 20%
If someone makes 50k then, they will pay 0 for the first 5k, then I need to calculate 10% for the next 10k, 15% for next 20k, and finally 20% for the 15k over 35k.
Obviously, the first bracket is the easiest one. I was thinking using a loop but I don't think I can use while loop.
Can you you guys give me ideas(no code of course) on how should I break this up?
1. If N >= 35000, then they pay 20% of (N - 34999), 15% of 20000, and 10% of 10000
2. If N > 14999 and N < 35000, then they pay 15% of (N - 14999) and 10% of 10000
3. If N > 4999 and N < 15000, then they pay 10% of (N - 4999)
4. If N < 5000 then they pay nothing
1) total amount < 5000?
1.1)yes: final amount is the total amount. done.
1.2)no: substract 5000 from total and add to the final amount.
2) total amount < 10000?
2.1)yes: add 90% of the total amount to the final amount. done.
2.2)no: substract 10000 from the total, add 90% (9000) of that to the final amount.
3) total amount < 20000?
3.1)yes: Add 85% of total to final amount. done.
3.2)no: substract 20k and add 85% (17000) of that to final.
4) add 80% of total amount to final. done.
taxes are total - final.
Could also easily be generalized, but that might be beyond you at your current stage.
I am looking at your solutions helps me think how I am going to approach it. I do need to create a loop and use break to exit the loop with negative amounts (part of the homework).
@Hanst99:
In my first try, I kind of wrote it like you are talking about but I am sure I made a mistake because it would not calculate taxes on amounts greater than 5k.
I will work with the bigest amount first and work my way down but I do need a lop.
I do need to create a loop and use break to exit the loop with negative amounts (part of the homework).
That loop is just to get input though. You would ask the user for input in a loop and stop when the user inputs a negative number. A loop is not required for the tax calculation unless you generalize it.