¿Is this program correct and well written?

2 次查看(过去 30 天)
Hello everyone, I need some help, I've just written the following code but I don't know if this is written correctly according to the text. I hope you can see if there are mistakes.
Sorry, english is not my native language.
TEXT:
A computer provider offers 10% discount, if the product costs $ 1 million or more. Also, independently offers a 5% discount if the brand is ABACO. Determine how much will pay a client for purchasing a computer, including tax.
TAX=Product Price * 0.16
CODE:
clear all
clc
M = input('Enter de computer''s brand: ', 's');
P = input('Enter the computer''s price: ');
TAX = P*0.16;
ABACO = 0.05;
if M==ABACO;
PA=P-(P*ABACO)+TAX;
fprintf('The purchase price is %d.\n',PA)
elseif M~=ABACO;
PB=P+TAX;
fprintf('The purchase price is %d.\n',PB)
elseif P>=1000000;
PC=P-(P*0.1)+TAX;
fprintf('The purchase price is %d.\n',PC)
end
Thanks.
  10 个评论

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2012-11-21
I can see you're eventually going to need to know this FAQ entry: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F because you're comparing floating point numbers.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by