self service checkout machine
이전 댓글 표시
Hi i need to use MATLAB to create a self service checkout machine that gives the user the optimal change using the formula -
change = payment - puchase
using valid australian coins and notes
댓글 수: 6
Steven Lord
2022년 7월 15일
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 free MATLAB Onramp tutorial 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.
Lauren
2022년 7월 18일
Lauren
2022년 7월 18일
Steven Lord
2022년 7월 18일
Can you walk through a problem manually? According to Wikipedia possible coin denominations are 5c, 10c, 20c, 50c, $1, and $2. [Let's leave out the discontinued 1c and 2c.]
So if I gave you a tray with a bunch of coins of each of those denominations and asked you to give me $4.65 how would you go about determining what coins to give me? Be methodical; I don't just want the answer I want you to think about how you determined the answer.
Once you've solved that problem, can you generalize it to any amount of change?
If you can do that, can you then determine how to translate your manual algorithm into MATLAB code?
Lauren
2022년 7월 18일
Steven Lord
2022년 7월 18일
Don't worry about the MATLAB code for right now. Assume you have an adequate supply of 5c, 10c, 20c, 50c, $1, and $2 coins. Write out in words not code the procedure you'd follow manually for giving $4.65 in change. Imagine you're trying to teach a child how to complete that task, so don't handwave any of the steps.
Do you start off with the 5c coins, the $2 coins, or one of the other denominations?
답변 (1개)
How about this? Is this what you expected?
change = 978;
% Ausie coins
coins = [1 2 5 10 20 50 100 200];
numCoins = zeros(size(coins)); % memory allocated
%
for i=numel(coins):-1:1
numCoins(i) = fix(change/coins(i));
change = mod(change,coins(i));
end
bar(coins,numCoins);
coins
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

