C++ Algorithmn

Hi People, I need your help,

I would like to know where to find documentation on c++ Algorithm. For exemple, how many ways can I represent a 5 dollar bill if I have loonies, quarters, dimes and nickles ?

Documentation would be greatly appreciated.

Thank You,

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

There are many places to find various C++ algorithms.

http://www.codeguru.com is a great place. You can find the C++ algorithms page from their home page, or just follow this link: http://www.codeguru.com/Cpp/Cpp/algorithms/.

They also have a lot of sample programs and non-algorithm specific solutions for a wide variety of problems.

http://www.codeproject.com is a great palce that deals mostly with MFCs. Their algorithm section is located at http://www.codeproject.com/cpp/#Algorithms.

MSDN is another good place to find algorithms and samples. If you don't have it installed on your computer, you can go to their website at http://msdn.microsoft.com. Typing "algorithms" into their search page will bring up quite a few of them. You can of course be more specific in your searches.

Finally, try google. If you know the general type of algorithm you want, you can find it that way.
read the comments before count_combos function.

  File: change.cpp
  Date: 08.13.2003
  Author: Jaydutt Shukla
  Purpose: This program asks for amount of money (in cents) and outputs the number of
  ways in which change can be given back for amounts <= MAX

#include <iostream>
#include <iomanip>
using namespace std;

const int MAX=2000; //will calculate # of combos only if amount <= MAX. requires very deep recursion

const int denoms[]={1, 5, 10, 25, 50, 100, 200, 500, 1000, 2000, 5000, 10000}; //const array for denominations

unsigned long  count_combos(int, int=0);

int main(){
    int cents=0, copy=0;
    cout << "Enter amount in cents: ";
    cin >> cents;
    copy = cents;
    if(cents <= MAX){
      cout << "Most efficient change is: \n";
      if(cents ==0){
          cout << "0 x $   0.00" << endl;
          cout << "Change can be given in " << count_combos(copy) << " different ways" << endl;
          return 0;
      for(int i=11; i>=0; i--){
            cout << cents/denoms[i] << " x " << "$ "
                 << setprecision(2) << setiosflags(ios::fixed) << setw(6)
                 << denoms[i]/100.0 << endl;
          cents %= denoms[i];
      cout << "Change can be given in " << count_combos(copy) << " different way(s)" << endl;
      cout << "Amount exceeds the limit." << endl;
    return 0;

 Recursive function:
 Start with pennies and denom d
 counter = 1;
 Determine how many d's do you want. range = [0, amount/d). use a for loop
   recurse with remaining pennies and next higher denomination
   Add this number to counter
   Increment # of d's

 ... and there are stopping conditions.
/* After you understand the working of this fcn:
   to extend this fcn for higher denominations append those to the const array denoms;
   change MAX to the max amount you want
unsigned long count_combos(int amount, int d){ //d == index into denoms array
    unsigned long count = 1;
    if(amount > MAX) return 1;   //do not exceed MAX denomination
    if(amount == 0) return 1;
    if(denoms[d] > amount) //Example: there is no way you can give out 1 cent using nickels
      return 0;
    /* The only problem occurs when starting amount == 0
       should the answer be 0 or 1? I chose 1. see previous line */
    for(int i=0; i<amount; i += denoms[d+1])
      count += count_combos(amount - i, d + 1);
    return count;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
C-beginAuthor Commented:
hey guys thank you very much,

I will try to read a bit more, for now....how do I split the points ?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.