if-else statement question

조회 수: 4 (최근 30일)
Bryan Lee
Bryan Lee 2020년 8월 4일
댓글: Steven Lord 2020년 8월 4일
please give me some idea for this question,thank you.
  댓글 수: 3
Rafael Hernandez-Walls
Rafael Hernandez-Walls 2020년 8월 4일
use the structure: IF -ELSEIF -ELSE -END
Steven Lord
Steven Lord 2020년 8월 4일
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.

댓글을 달려면 로그인하십시오.

답변 (1개)

Udoi
Udoi 2022년 6월 22일
We can simulate the whole scenario.
At first we must take the input for the name of the customer,his address,his amount of purchase and the type of purchase.
We can use nested if-else statements in MATLAB to calculate the appropriate discount for a specied amount of purchase within a particular range.
Code snippet:
prompt = "Enter the name of the customer ";
name = input(prompt,"s")
prompt = "Enter the address of the customer ";
address = input(prompt,"s")
prompt = "Enter the amount purchased by the customer";
amount = input(prompt)
prompt = "Enter the type of the purchase by the customer?For laptop,type L and for desktop type D ";
type = input(prompt,"s")
if(type=='L')
if(amount>=0 && amount<=250)
end
discount=(amount*0)/100;
amount=amount-discount;
if(amount>=251 && amount<=570)
discount=(amount*5)/100;
amount=amount-discount;
end
if(amount>=571 && amount<=1000)
discount=(amount*7.5)/100;
amount=amount-discount;
end
if(amount>1000)
discount=(amount*10)/100;
amount=amount-discount;
end
disp(amount);
end
if(type=='D')
if(amount>=0 && amount<=250)
end
discount=(amount*5)/100;
amount=amount-discount;
if(amount>=251 && amount<=570)
discount=(amount*7.6)/100;
amount=amount-discount;
end
if(amount>=571 && amount<=1000)
discount=(amount*10.0)/100;
amount=amount-discount;
end
if(amount>1000)
discount=(amount*15)/100;
amount=amount-discount;
end
disp(amount);
end
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial
Follow the link(https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB

카테고리

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