self service checkout machine

조회 수: 3 (최근 30일)
Lauren
Lauren 2022년 7월 15일
댓글: Steven Lord 2022년 7월 18일
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
Lauren
Lauren 2022년 7월 18일
Thats what im confused about, im not sure how to get the optimal change with a matlab code
Steven Lord
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개)

Hiro Yoshino
Hiro Yoshino 2022년 7월 15일
편집: Hiro Yoshino 2022년 7월 15일
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
coins = 1×8
1 2 5 10 20 50 100 200

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by