if-else statement question

1 回表示 (過去 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 Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by