Bill shortage: Basic Coding
Okay, first up, I'm a bit rusty with C++, so I apologize if this isn't formatted correctly.

But, the first thing that leaps out is "Single Responsibility Principle".  Aka - each function should be responsible for one thing and have one reason to change.

Or in short: don't write everything in your Main().

What is your Main() doing, at a high level?  It's:


Grabbing inputs for how many people and what bills they have
It's setting up the register (with no bills in it)
It's looping through each person
It's checking how that person impacts the current register
It's outputting the success/failure of the venture.


Awesome!  So... what should your main look like in an abstract sense?

main()
{
    int patronCount = GetPatronCount();
    int[] billAmounts = GetBillAmounts();
    int[] register = SetUpRegister();
    for (i = 0; i &lt; patronCount; i++)
    {
        bool wasAbleToMakeChange = MakeChangeForPatron(register, billAmounts[i]);
        if (!wasAbleToMakeChange)
        {
            // code to return out with failure
        }
    }
    // code to return success
}


So... why would we do this?  Well, because right now, if you need to tweak a line of code in your code?  That could have ramifications all throughout your function.  You can't exactly digest it in small bits, because everything has 'scope' with everything else.  And if you needed to change something, you'd have to consider how that change affects everything else in that function.

This is incredibly important as you grow as a programmer - you're going to be changing code a lot more than you're going to be composing it - and the simpler you can make changing it, the better off you'll be.

Also, it becomes much easier to see what the program does.  Because the function names and variable names document exactly what it's doing at a high level.  It's getting a patron count.  Imagine someone reading your code (and only your code - no explanations)... how quickly would they figure out what it's doing?  Contrast that to my version's main().  So if someone else needs to work with your code (or if you need to work with it, but don't remember it very well) it'll be able to be grok'ed a lot quicker.