problems in switch and if commands

2 views (last 30 days)
Hi guys I am having problems in solving this question can some one help me out please ? :)
I need to use the switch and if commands.
  1 Comment
Image Analyst
Image Analyst on 10 May 2013
Edited: Image Analyst on 10 May 2013
Notice: Charlene edited the vast majority of her question away, probably because it was a homework question.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 9 May 2013
Make up a 4 by 6 matrix with those numbers in it.
Then ask your user, say with inputdlg(), what their income is. By knowing that, you know what matrix row to use. You can use a switch for that.
Then use questdlg() to ask whether they are married. By knowing that you know what columns to use, 1-3, or 4-6. You can use an if statement to set the column numbers.
Finally, simply look up the required RATE and DEDUCT from the proper row and columns.
Not hard at all. Give it a shot.

More Answers (1)

Image Analyst
Image Analyst on 9 May 2013
I can do some of it but not all of it for you, because it's your homework, not mine.
rateTable = [...
8500 0 0 11900 0 0
14500 0.15 1275 21200 0.15 1785
19500 0.25 2725 28700 0.25 3905
inf 0.35 4675 inf 0.35 6775]
% Ask user for a number.
defaultValue = 20000;
titleBar = 'Enter a value';
userPrompt = 'Enter your income';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
income = str2double(cell2mat(caUserInput));
% Check for a valid integer.
if isnan(income)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
income = defaultValue;
message = sprintf('I said it had to be a number.\nI will use %d and continue.', income);
uiwait(warndlg(message));
end
message = sprintf('Are you married');
button = questdlg(message, 'Married?', 'Yes', 'No', 'Yes');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Yes')
income < rateTable(:, 4)
rowToUse = find(income < rateTable(:, 4), 1, 'first')
deduct = % You do this part
theirRate = % You do this part.
else
income < rateTable(:, 1)
rowToUse = find(income < rateTable(:, 1), 1, 'first')
deduct = % You do this part
theirRate = % You do this part.
end
% Now you compute the tax based on rate and deduct.

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!