how to create a function, and make the function to take items as its only parameter

조회 수: 1 (최근 30일)
.
  댓글 수: 1
Stephen23
Stephen23 2020년 2월 1일
편집: Stephen23 2020년 2월 1일
"I will greatly appreciate it if I am given ... the solution to the assignment."
Which of course you cannot hand in as your own work:
Or are you planning on informing your teacher/tutor/professor that what you submit is not your own work?

댓글을 달려면 로그인하십시오.

채택된 답변

edward holt
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
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
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개)

henry tochukwu
henry tochukwu 2020년 2월 1일
please i only wanted a guideline on how to do the assignment. i won't repeat such again.
thanks

카테고리

Help CenterFile 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!

Translated by