if-else statement question

5 vues (au cours des 30 derniers jours)
Bryan Lee
Bryan Lee le 4 Août 2020
Commenté : Steven Lord le 4 Août 2020
please give me some idea for this question,thank you.
  3 commentaires
Rafael Hernandez-Walls
Rafael Hernandez-Walls le 4 Août 2020
use the structure: IF -ELSEIF -ELSE -END
Steven Lord
Steven Lord le 4 Août 2020
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.

Connectez-vous pour commenter.

Réponses (1)

Udoi
Udoi le 22 Juin 2022
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

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by