필터 지우기
필터 지우기

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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by