The IRS allows a taxpayer to contribute to a ROTH
Program
The IRS allows a taxpayer to contribute to a ROTH IRA, if his/her income is not over a specified limit and his/her filing status allows contributions.
You will write a program that carries out the logic of a simplified worksheet to determine how much may be contributed to a ROTH IRA.
Sample IRS-like instructions for each line of the worksheet: This worksheet may not be used by any taxpayer who is married filing separately, and did not live with their spouse any time during the year. | |
Line 1 | Determine maximum possible ROTH IRA contribution limit. If under age 50, enter $5,500 on line 1. Otherwise, enter $6,500 on line 1. |
Line 2 | Enter the modified Adjusted Gross Income for IRA purposes on line 2. |
Line 3 | Determine the Income Limit amount for full contributions, according the filing status from the list below and enter limit on line 3: Single or Head of household - $ 112,000 Married filing jointly or Qualifying Widow(er) - $ 178,000 Married filing separately and lived with spouse any time during year – $ 0 |
Line 4 | Determine if a reduction to the contribution limit is necessary. Is the amount on line 2 less than or equal to the amount on line 3? Yes. Can contribute up to maximum contribution limit. Skip lines 4 – 8 and enter the amount from line 1 on line 9 (ignore line 9 instructions) No. Contribution limit may be reduced. Subtract line 3 from line 2 and enter the amount on line 4 and continue. |
Line 5 | Determine division amount to use, depending on filing status, and enter it on line 5: Single or Head of household - $ 15,000 Married filing jointly or separately, or Qualifying Widow(er) – $ 10,000 |
Line 6 | Determine reduction percentage. Divide line 4 by line 5 and determine the floating point result rounded to 3 places. Is the result is 1.0 or more? Yes. Cannot contribute to a ROTH IRA. Skip lines 6 – 8 and enter 0 on line 9 (ignore line 9 instructions) No. Contribution limit will be reduced. Enter the calculated reduction percentage rounded to 3 places on line 6. |
Line 7 | Determine reduction amount. Multiply line 6 by line 1 and enter the result on line 7 |
Line 8 | Determine possible contribution limit. Subtract line 7 from line 1. Round the result up to the nearest $10, and enter result on line 8 |
Line 9 | Enter the larger value: line 8 or $200. This line 9 amount is your ROTH IRA contribution limit. |
Determine if the taxpayer should continue, or if the program should exit.
oIf the taxpayer’s filing status is married filing separately
oAsk if the taxpayer lived with his/her spouse at any time during the year.
(User input can be in either upper or lowercase.)
§ If the answer is no, the taxpayer may not contribute to a ROTH IRA. contribution.
§ Display a message saying so (see Sample 2 Output below) and pause.
§ Then return from main with exit code of 1, to indicate that the program returned before line 1.
§ return 1;
oIf the program did not exit, continue.
Read and store the taxpayer’s age.
Perform a test to determine and store the amount for line 1.
Read and store Adjusted Gross Income for IRA purposes for line 2.
Determine the line 3 income limit that applies for the filing status entered, and store the result.
oHINT: Store the filing status description in words into a string variable at the same time.
Display the Worksheet title and the first 3 lines (1 – 3) of the worksheet.
Perform the line 4 test to determine if the program needs to continue.
oIf line 2 is less than or equal to line 3
§ Display the amount from line 1 on line 9, and pause.
§ Then return from main with exit code of 4, to indicate that the program exited on line 4.
§ return 4;
oIf the program did not exit, continue.
Perform the necessary calculation for line 4 and store the result.
Determine the line 5 division amount to use for the filing status entered, and store it.
Display lines (4 and 5) of the worksheet.
Perform the necessary calculation for line 6 and store the result.
Perform the line 6 test to determine if the program needs to continue.
If the result is 1.0 or more, taxpayer cannot contribute to a ROTH IRA:
§ Display a message, and pause (see Sample 4 output)
§ Then return from main with exit code of 4, to indicate that the program exited on line 6.
§ return 6;
oIf the program did not exit, continue.
ROTH IRA Contribution Limit Worksheet
Filing Status: Married, Filing Jointly
1. Possible contribution limit: 5500.00
2. Adjusted Gross Income 180330.00
3. Income Limit: 178000.00
4. Amount over Limit: 2330.00
5. Division amount: 10000.00
6. Reduction Percentage: 0.233
7. Reduction Amount: 1281.50
8. Reduced contribution limit: 4220.00
9. Maximum ROTH IRA Contribution Limit 4220.00
Perform the necessary calculation for line 7 and store the result.
Call a user-defined function to find the amount for line 8 and store the value returned.
ü The user-defined function will have two input arguments:
theline 1 amount and the line 7 amount
ü The function will subtract line 7 from line 1.
ü The function will round the result to the nearest $10.
Hint: Divide by 10, apply the pre-defined ceil function to the resulting value, and then multiply that by 10.
ü The function will return the result.
ü Examples:
oInput arguments of line 7 = 475 and line 1 = 5500
would return 5030
oInput arguments of line 7 = 500 and line 1 = 6500
would return 6000
ü No other computations should be performed within this function.
Perform the line 9 test to determine the final contribution limit and store the result.
Display lines 6 through 9 of the worksheet, making sure that line 6 is displayed to 3 decimal places (see Sample 1 Output below).
Sample 1 Output (no early exit – uses sample inputs 1 from program description)
ROTH IRA Contribution Limit Worksheet
Filing Status: Single
1. Possible contribution limit: 6500.00
2. Adjusted Gross Income 66000.00
3. Income Limit: 112000.00
9. Maximum ROTH IRA Contribution Limit 6500.00
ROTH IRA Contribution Limit Worksheet Program
1 - Single
2 - Married, Filing Jointly
3 - Head of Household
4 - Qualifying Widow(er)
5 - Married, Filing Separately
Enter your filing status from above (1-5): 1
Enter your age: 65
Enter Adjusted Gross Income for IRA purposes: 66000
Contributions to a ROTH IRA are not allowed for taxpayers who:
-File as Married Filing Separately
-Did not live with their spouse for any part of the year.
Therefore, you cannot contribute to a ROTH IRA!
ROTH IRA Contribution Limit Worksheet Program
1 - Single
2 - Married, Filing Jointly
3 - Head of Household
4 - Qualifying Widow(er)
5 - Married, Filing Separately
Enter your filing status from above (1-5): 5
Did you live with your spouse for any part of the year (Y/N)? n
ROTH IRA Contribution Limit Worksheet
Filing Status: Head of Household
1. Possible contribution limit: 5500.00
2. Adjusted Gross Income: 128000.00
3. Income Limit: 112000.00
4. Amount over Limit: 16000.00
5. Division amount: 15000.00
Income too high – You cannot contribute to a ROTH IRA!
ROTH IRA Contribution Limit Worksheet Program
1 - Single
2 - Married, Filing Jointly
3 - Head of Household
4 - Qualifying Widow(er)
5 - Married, Filing Separately
Enter your filing status from above (1-5): 3
Enter your age: 35
Enter Adjusted Gross Income for IRA purposes: 128000
Make sure there are a couple of blank lines AFTER all input has been entered and BEFORE the worksheet is displayed.
The filing status should be displayed in words (i.e. not a number), lined up on the right with the figures below it.
A married filing separately filing status may cause the program to exit without displaying any of the worksheet (see sample 2 above).
The decision on line 4 may cause skipping the display of lines 4 - 8 (see sample 3 above).
The decision on line 6 may cause an exit after line 5 (see sample 4 above).
If neither of the above happens, all lines of the worksheet will be displayed (see sample 1 above).
12 years ago
Purchase the answer to view it

- rothiraapp.zip