Anonymous user
Count the coins: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments, added support for fractional cent glyphs, used templates for the output sections.
m (→{{header|REXX}}: added/changed whitespace and comments, added support for fractional cent glyphs, used templates for the output sections.) |
|||
Line 2,538:
numeric digits 20 /*be able to handle large amounts of $.*/
parse arg N $ /*obtain optional arguments from the CL*/
if N='' | N="," then N=
if $='' | $="," then $= 1 5 10 25
if left(N, 1)=='$' then N= 100 * substr(N, 2)
coins= words($)
NN= N; do j=1 for coins
_= word($, j)
if _=='1/2' then _=.5
if _=='1/4' then _=.25
$.j=
end /*j*/
_= n//100;
if _=0 then do; NN= '$' || (NN%100); cnt=
end /*show the amount in dollars, not cents*/
say 'with an amount of '
say 'ways to make change with coins of the following denominations: ' $
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
MKchg: procedure expose $.; parse arg a,k
<pre>
with an amount of $1, there are 242
ways to make change with coins of the following denominations: 1 5 10 25
</pre>
<pre>
with an amount of $1, there are 29,034,171
Line 2,582 ⟶ 2,584:
numeric digits 20 /*be able to handle large amounts of $.*/
parse arg N $ /*obtain optional arguments from the CL*/
if N='' | N="," then N=
if $='' | $="," then $= 1 5 10 25
if left(N,1)=='$' then N= 100 * substr(N, 2)
!.= .;
if _=='½'
if _=='¼'
_= n // 100;
if _=0 then do; NN= '$' || (NN%100); cnt=
end
say 'with an amount of '
say 'ways to make change with coins of the following denominations: ' $
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
MKchg:
<pre>
with an amount of $1,000, there are 13,398,445,413,854,501
Line 2,623 ⟶ 2,625:
numeric digits 20 /*be able to handle large amounts of $.*/
parse arg N $ /*obtain optional arguments from the CL*/
if N='' | N="," then N=
if $='' | $="," then $= 1 5 10 25
X=
if left(N,1)=='$' then do /*the amount has a leading dollar sign.*/
_= substr(N, 2)
if \isNum(_) then call ser "amount isn't numeric: " N
N= 100 *
end
max$= 10 ** digits()
if \isNum(N) then call ser X " amount isn't numeric."
if N=0 then call ser X " amount can't be zero."
if N<0 then call ser X " amount can't be negative."
if N>max$ then call ser X " amount can't be greater than " max$'.'
coins= words($); !.= .; NN= N;
@.=
do j=1 for coins; _= word($,
if _=='½' | _=="1/2
if _=='¼' | _=="1/4
if \isNum(_) then call ser ? "coin value isn't numeric."
if _<0 then call ser ? "coin value can't be negative."
if _<=0 then call ser ? "coin value can't be zero."
if @._ then call ser ? "coin was already specified."
if _<p then call ser ? "coin must be greater than previous:" p
if _>N then call ser ? "coin must be less or equal to amount:" X
@._= 1; p=
$.j=
end /*j*/
_= n // 100;
if _=0 then do; NN= '$' || (NN%100); cnt=
end
say 'with an amount of '
say 'ways to make change with coins of the following denominations: ' $
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
isNum:
ser:
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
MKchg:
=={{header|Ring}}==
|