フィルターのクリア

problems in switch and if commands

2 ビュー (過去 30 日間)
Charlene
Charlene 2013 年 5 月 9 日
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 件のコメント
Image Analyst
Image Analyst 2013 年 5 月 10 日
編集済み: Image Analyst 2013 年 5 月 10 日
Notice: Charlene edited the vast majority of her question away, probably because it was a homework question.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2013 年 5 月 9 日
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.

その他の回答 (1 件)

Image Analyst
Image Analyst 2013 年 5 月 9 日
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.
  1 件のコメント
Charlene
Charlene 2013 年 5 月 9 日
thanks a lot i really appreciate it

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by