clear all; clc; % Obtain a cent amount from the user change = input(\' Enter a c
ID: 3858065 • Letter: C
Question
clear all;
clc;
% Obtain a cent amount from the user
change = input(' Enter a cent amount: ');
% Verify the input must be an interger and less than 99
if mod(change,1) ~= 0 || change < 0 || change > 99
error('Change unvalidated');
end
% Assign the initial values of number of each coins
q = 0;
d = 0;
n = 0;
while (change > 0 && change < 100)
% Frist, count the number of quarters
if change >= 25
change = change - 25;
q = q+1;
% Count the number of dimes
elseif change >= 10
change = change - 10;
d = d +1;
% Count the number of nickles
elseif change >= 5
change = change - 5;
n = ceil(change/5);
end
% Count the total coins that counted
cointcount = q+d+n;
end
fprintf('Average number of coins %5.2f ', cointcount);
In this case, imagining that we are eliminating the penny from the circulation. The code still doesn't work when I insert the function ceil. Could anyone help me with this? Thank you.
Explanation / Answer
If your objective is to get the number of coins,this code does it
clear all;
clc;
% Obtain a cent amount from the user
change = input(' Enter a cent amount: ');
% Verify the input must be an interger and less than 99
if change < 0 || change > 99
error('Change unvalidated');
end
% Assign the initial values of number of each coins
q = 0;
d = 0;
n = 0;
while (change > 0 && change < 100)
% Frist, count the number of quarters
if change >= 25
change = change - 25;
q = q+1;
% Count the number of dimes
elseif change >= 10
change = change - 10;
d = d +1;
% Count the number of nickles
else
n = ceil(change/5);
change=-1;
end
% Count the total coins that counted
end
cointcount = q+d+n;
fprintf('Average number of coins %5.2f ', cointcount);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.