Should I determine if income < 15k before starting my for loop?
No. What if there is a tax on income below the bottom breakpoint?
Income
|
Breakpoint |
Tax pct |
Common
Array index |
From 0 to |
$15,000 |
0% |
0 |
From 15K to |
$45,000 |
15% |
1 |
From 45K to |
$65,000 |
20% |
2 |
From 65K to |
$85,000 |
25% |
3 |
above 85K |
|
??? |
N/A |
You should check if Income is negative, otherwise the function will return a negative tax
Another question I have, say income is greater than 65k, my final break point, (at which point everything above 65k is charged at a fixed %). Should I just add another scenario to my if statement?
Technically, the Final Breakpoint is 85K.
That is a judgement call. Does the professor like you to follow the rules EXACTLY? Does he/she like to see you use some initiative? My answer might be inappropriate because I am an arrogant genius smart-ass showoff with no social sense at all.
I think you have a good beginner's levl of understanding of Arrays now, so I will attempt to explain the required algorithmic logic for this assignment. BTW, tell me before this assignment is due so I can cut to the chase, so to speak.
For Programming purposes, stop thinking of Taxes. Mentally refer to the Tax Pct column/Array as the Multiplier Array. Reason: Prgrmmers can't look at any regular value type like a member of society does. We must only see them as items to be manipulated. Contrary-wise, we must look at the values the same way others do while we run What-If scenarios thru our pointy little heads. Your professor does not see this as a Tax problem, but only as a numbers problem. So our What-Ifs must also see it as a numbers problem.
Refer to the expanded "Tax" table above.
Previous Breakpoint,AKA arrBreakpoint(i-1), herein referred to as FromPoint
Code algorithm:
First step: Run the Code only on positive Income
If Income <= 0 Then Exit Function
Then: For each income bracket, Multiply the TaxPct by only the part of Income that falls in that Bracket.
Special case of First array index. (if existed, FromPoint.Value = 0):
If i = LBound(Array) then
Min(Income, arrBreakPoint(i)) * TaxPct
End If
Other Indexes:
Min(Income - FromPoint, BreakPoint -FromPoint) * TaxPct
iterate thru Arrays, LOOP
Special case of Income > i = UBound(Array) AKA > 85K. If you decide to "Tax income above 85K:
If Income > arrBreakPoint(i) then
(Income - arrBreakPoint(i)) * arTaxPct(i)
End Function here
About "Min()": Min is a function that returns the minimum of values inside the brackets. Example:
A = 5
B = 3
X = Min(A, B, A/B, A-B, A+B, B/A, B-A)
X = -2
I have tried hard to NOT cheat for you so that if needed, you can point your professor at this thread.