Message Boards Message Boards

GROUPS:

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

Posted 4 months ago
648 Views
|
2 Replies
|
1 Total Likes
|

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:
2 Replies

His In[1] on page 116 is

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

Compare with your In[1].

Posted 4 months 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*)
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