Bills dispenser machine
This is a tricky problem to solve.  In the general case, the change-making-problem requires dynamic-programming to solve.  It is possible to write a simpler algorithm that works for $20 and $50 only, but yours is buggy:

This machine only dispense in $20 and $50 bills only
Enter in the amount to be withdraw : 
30
remE : 10

(2) Number of $50 bills : -1
(2) Number of $20 bills : 4
(2) Number of bills dispensed is 3


Furthermore, if (remE &gt;= 10 || remE &gt;= 20 ) in the second solution looks wrong.



If I had to write a quick-and-dirty non-generalized solution for $50 and $20, I would write it this way:

#include &lt;cassert&gt;
#include &lt;iostream&gt;
#include &lt;iomanip&gt;

/**
 * Composes the given amount as a number of 50-dollar bills and 20-dollar
 * bills (as out-parameters).  Returns the total number of bills needed, or -1
 * if the amount cannot be formed.
 */
int split_50_20_bills(int amount, int *num_50, int *num_20) {
    if (amount &lt; 0 || amount == 10 || amount == 30 || amount % 10) {
        return -1;
    } else {
        *num_50 = (amount % 20) ? ((amount - 50) / 100) * 2 + 1 :
                                  (amount / 100) * 2;
        *num_20 = (amount - 50 * *num_50) / 20;
        assert(amount == 50 * *num_50 + 20 * *num_20);
        return *num_50 + *num_20;
    }
}

int main()
{
    for (int amt = 0; amt &lt;= 1000; amt += 10) {
        int num_50, num_20;
        int total = split_50_20_bills(amt, &amp;num_50, &amp;num_20);
        std::cout &lt;&lt; std::setw(4) &lt;&lt; amt;
        if (total &lt; 0) {
            std::cout &lt;&lt; " cannot be formed\n";
        } else {
            std::cout &lt;&lt; " = " &lt;&lt; std::setw(2) &lt;&lt; num_50 &lt;&lt; " x $50 + "
                               &lt;&lt; std::setw(2) &lt;&lt; num_20 &lt;&lt; " x $20 ("
                               &lt;&lt; std::setw(2) &lt;&lt; total &lt;&lt; " bills)\n";
        }
    }
}


Note that one function passes back four pieces of information:


Whether it's possible to form the amount
If so, how many bills it will take altogether
How many $50 bills
How many $20 bills