Message Boards Message Boards

0
|
7923 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Use CountChange defined in "Wellin - Essential of Programming" Page 117?

Posted 6 years ago

Why does my function CountChange not work the same way, Wellin says it does on page 117 of his book Essential of Programming...?

CountChange is CountChange[coins_Llist] := Total[coins /. {p -> .01, n -> .05, d -> .10, q -> .25}]
CountChange[{p, q, q, d, d, p, q, q, d, d}]

Why do I not receive output of "1.42". Please see attach

Attachments:
POSTED BY: Samuel Kohn
2 Replies
Posted 6 years ago

The function should be defined as:

CountCoins[coins_List] (*you have defined the pattern _Head wrongly. First letter of the "list" should be capital*)
POSTED BY: Girish Arabale

His In[1] on page 116 is

coins={p,p,q,n,d,d,p,q,q,p}

Compare with your In[1].

POSTED BY: Raspi Rascal
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract