how to create a function, and make the function to take items as its only parameter
1 次查看(过去 30 天)
显示 更早的评论
.
1 个评论
采纳的回答
edward holt
2020-2-1
The below should do it.
x = str2double(inputdlg('number of items purchased:'))
% asks for the number of items purchased, and converts it from string to a double
shipping(x)
%runs the below function with the number of items entered above as input
function price = shipping(x) %create a function, shipping, which takes one input, and outputs the price.
if x == 1
price = 3950.75; %if one item is purchased, the price is just 3950.75
else if x == 0
price = 0; %if no items are purchased, the price is 0.
else if x > 1
price = 3950.75 + (825.50 * (x-1)); %if more than one item is purchased, the price is 3950.75 for the first item, and 825.50 for the rest of the items, i.e. (x - 1)
end
end
end
end
2 个评论
Walter Roberson
2020-2-1
We discourage people from providing complete homework solutions, especially when the person asking has not shown that they have tried anything.
edward holt
2020-2-1
Walter, my apologies. I'm quite new here, and was too eager to help. Lesson learned. I will endeavour to guide. Sorry. Thank you for the advice.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!