I am in need of assistance with MatLab! It is that time of year again — tax seas
ID: 3673809 • Letter: I
Question
I am in need of assistance with MatLab!
It is that time of year again — tax season! Before April 15th arrives you decide to write a program to compute Schedule A (Itemized Deductions) for Form 1040 Federal Income Tax. To correctly calculate the total itemized deductions, you will first need to prompt the user for his/her adjusted gross income (AGI). To simplify the input required for Schedule A, you will write a program that will prompt the user for the amount of each section rather than each line (see below). Prompt for the following input:
Adjusted Gross Income (AGI)
Medical and Dental Expenses (lines 1 – 4 on Schedule A)
Taxes You Paid (lines 5 – 9 on Schedule A)
Interest You Paid (lines 10 – 15 Schedule A)
Gifts to Charity (lines 16 – 19 Schedule A)
Casualty and Theft Losses (line 20 Schedule A)
Job Expenses and Certain Miscellaneous Deductions (lines 21 – 27 Schedule A) Other Miscellaneous Deductions (line 28 Schedule A)
After reading in the input you must verify the user has entered a valid number for each entry. Any value less than zero, including the AGI, is considered invalid. Output an entry was invalid and do not continue calculating Schedule A. Note, when checking for this condition, your code must use only one if- statement that incorporates logical operators (&&, || or ~) to decide whether or not to continue.
For Medical and Dental Expenses, the value entered must be processed so that only that amount which exceeds 10% of the AGI is deducted. For example, if your income is $50,000, you may only deduct the amount that exceeds ($50,000 * .10) or $5,000. So, if your expenses are $6500 then you may deduct ($6500 - $5000), or $1,500. If your expenses are $4000 then you may NOT deduct anything. Use an if- statement to determine what can be deducted.
Similarly, Job Expenses and Certain Miscellaneous Deductions may only be considered if they exceed 2% of your AGI. So again, if your AGI is $50,000, you may only deduct that amount which exceeds ($50,000 * .02) or $1,000. So, if your expenses/deductions are $3,250, you may deduct ($3,250 - $1000) or $2,250. If your expenses/deductions are $500, you may not deduct anything. As in the case of medical and dental expenses, use an if-statement.
Finally, add up the total itemized deductions: medical and dental expenses, taxes you paid, interest you paid, gifts to charity, casualty and theft losses, job expenses and certain miscellaneous deductions, and other miscellaneous deductions. If the total exceeds your AGI then your total itemized deductions are capped at your AGI. Assuming your AGI is $50,000, if your total itemized deductions add up to $51,647 (say you bought a VERY expensive home and are deducting a lot of interest) then you may only claim $50,000 as your total itemized deductions.
Input Data
- Adjusted Gross Income (AGI)
- Medical and Dental Expenses (lines 1 – 4 on Schedule A)
- Taxes You Paid (lines 5 – 9 on Schedule A)
- Interest You Paid (lines 10 – 15 Schedule A)
- Gifts to Charity (lines 16 – 19 Schedule A)
- Casualty and Theft Losses (line 20 Schedule A)
- Job Expenses and Certain Miscellaneous Deductions (lines 21 – 27 Schedule A)
- Other Miscellaneous Deductions (line 28 Schedule A)
Output Data
-The total itemized deductions you will list on line 38 of Form 1040 of your Federal Income Tax.
Begin your program with
clc
clear
to clear the Command Window and Workspace windows, respectively.
Prompt (ask) the user for the input variables using MATLAB’s input command.
First determine if all of the input variables are valid using just 1 if-statement. If not, output an invalid entry occurred. If so, continue to step 4.
Determine the allowable medical and dental expenses: multiply the AGI by 10% (0.10) and subtract this value from medical and dental expenses (i.e., medical – 10%AGI). If the value is less than 0, then use 0 for this expense (use an if-statement).
Determine the allowable job expenses: multiply the AGI by 2% (0.02) and subtract this value from job expenses (i.e. jobExpenses – 2% AGI). As in the case of step 4, if the value is less than 0, use 0 for this expense (use an if-statement).
Finally determine the total itemized deductions, by adding up each deduction. Subtract this sum from the AGI, and, if it is negative, your deductions are more than your income (use an if- statement). This is not allowed so cap your deductions at your AGI.
Using Matlab’s fprintf command, output the total itemized deductions allowed.
8. Before each significant step, provide a comment explaining the step (do not comment every line of code).
Test Plan
Explanation / Answer
%Program: demo.m
%Read and check AGI is positive value
%else exit program
AGI = input('Enter Adjusted gross income:' );
if(AGI<0)
disp('Adjusted gross income value is invalid');
exit;
end
%read medical and dental expenses
%Determine the allowable medical and dental expenses
MedDental=input('Medical and Dental Expenses: ');
if((MedDental-0.10*AGI)<0)
MedDental=0;
else
MedDental=MedDental-0.10*AGI;
end
TaxesPaid=input('Enter Taxes You Paid: ');
InterestPaid =input('Enter Interest You Paid : ');
GiftsToCharity=input('Enter Gifts to Charity: ');
CasualtyTheftLosses=input('Enter Casualty and Theft Losses: ');
%Determine the allowable job and misc expenses
JobMiscDeductions=input('Enter Job Expenses and Certain Miscellaneous Deductions: ');
if((JobMiscDeductions-0.02*AGI)<0)
JobMiscDeductions=0;
else
JobMiscDeductions=JobMiscDeductions-0.02*AGI;
end
MiscDeductions=input('Enter Other Miscellaneous Deductions: ');
%find Total Itemized Deductions
TotalItemizedDeductions=MedDental+TaxesPaid+InterestPaid+GiftsToCharity+CasualtyTheftLosses+JobMiscDeductions+MiscDeductions;
difference=AGI-TotalItemizedDeductions;
% check for Allowable itemized deductions
if(difference<0)
disp('Your deductions are more than your income');
fprintf('total itemized deductions allowed: $%d',AGI);
else
fprintf('total itemized deductions allowed: $%d',TotalItemizedDeductions);
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.