フィルターのクリア

Loops question,I think its for loops

1 回表示 (過去 30 日間)
David Tejcek
David Tejcek 2019 年 7 月 2 日
コメント済み: Alex Mcaulley 2019 年 7 月 3 日
Hi everyone,
Could someone explain to me how to answer a question such as this:
Write a good which calculates the total cost of materials with one variable being units. If there are less than 1000 units made, the cost is 30c per unit. If there is more than 1000 units sold but less than 2000 units sold it is $100+ 10c per unit. If there is more than 2000 units sold it is $150 +5c per unit. Calculate the total cost of the units and display it as total cost.
Thanks

回答 (1 件)

Alex Mcaulley
Alex Mcaulley 2019 年 7 月 2 日
It is not difficult (No loops needed):
function cost = calculateCost(units)
if units < 1000
cost = %write the formula
elseif units > 2000
cost = %write the formula
else
cost = %write the formula
end
end
  2 件のコメント
Jan
Jan 2019 年 7 月 2 日
編集済み: Jan 2019 年 7 月 2 日
Almost. The exact formulation:
if units < 1000
% less than 1000 units
elseif units > 1000 & units < 2000
% more than 1000 units sold but less than 2000 units
elseif units > 2000
% more than 2000
end
Following the instructions, the code fails for units==1000 and ==2000.
"Calculate the total cost of the units and display it as total cost" - A funny formulation also: Can I display the total cost as every other than the total cost?
Nevertheless, Alex, I assume you solved, what was intented. +1
Alex Mcaulley
Alex Mcaulley 2019 年 7 月 3 日
Yes, you are right Jan. Following the statement, units == 1000 and units == 2000 are free XD

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by