TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALL
from: ALEX WALKER
date: 1997-11-03 14:46:00
subject: WTD Coin algorithm ideas

     Hi All
     I'm a student studying C++ programming.  I've got an assignment
     question where I don't even have an idea how to attack the 
     problem.  The program is to input a value (like $1. $2. $5..)
     and spit out a table showing all the different cominations of coins
     that could be used to make up that value.  So for $0.10 the table
     would look like:
     10 = 10
     10 = 5 + 5
     10 = 5 + 1 + 1 + 1 + 1 + 1
     10 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1
     At first I tried to do a series of for loops, 
     for ( five times ) 
         for ( coin < money ) 
               for ( coin < money )
                    for ( coin < money )
                    {    for ( coin < money )
                         {    cout << "+ 25 "; }
                         cout << " + 10";
                    }
                    cout << " + 5";      
               }
               cout << "+ 1";
         }           
     }
     But this just gave me a table of;
              10 + 10 + 10...
               5 + 5 + 5..
               1 + 1 + 1 + 1...
     I've looked at Permutations and combinations math wise but this
     method just gives me the number of permutations, not what they are.
     I'm not asking for code, just an idea of how to attack the question.
     Thanks for any ideas. 
... - InterNet E-Mail: awalker@spruce.nic.bc.ca -or- alex.walker@cgate.com
---
---------------
* Origin: Community Access Courtenay, BC (604) 338-4597 (1:3412/1)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.