I'm trying to make a program that tells you how much of each type of bill or coin you will receive as change after you enter the total amount of goods you are buying and the amount you are paying with. But my program takes in the total amount of goods and the amount you are paying with and then it stops. Here's my program -

/*
Change.cpp
*/

#include <cstdlib>
#include <iostream>
                                                                                                          
using namespace std;
                                                                                      
int main()
{
    double tot = 0;
    double cash = 0;
    double change = 0;                                                                          
    
    int hundreds = 0; // number of $100 bills
    int fifties = 0; // number of $50 bills
    int twenties = 0; // number of $20 bills
    int tens = 0; // number of $10 bills
    int fives = 0; // number of $5 bills
    int toonies = 0; // number of toonies
    int loonies = 0; // number of loonies
    int quarters = 0; // number of quarters
    int dimes = 0; // number of dimes
    int nickels = 0; // number of nickels
    int pennies = 0; // number of pennies
    
    cout << "Enter the total amount of your goods:" << endl;
    cin >> tot;

    cout << "Enter the amount you are paying with:" << endl;
    cin >> cash;
    
    change = cash - tot;
    
    while ( change > 100 ) {
        change = change - 100;
        hundreds = hundreds ++; 
        }
    
    while ( change > 50 ) {
        change = change - 50;
        fifties = fifties++;
        }
        
    while ( change > 20 ){
        change = change - 20;
        twenties = twenties++;
        }
        
    while ( change > 10 ) {
        change = change - 10;
        tens = tens++;
        }   
    
    while ( change > 5 ){
        change = change - 5;
        fives = fives++;
        }    
        
    while ( change > 2 ){
        change = change - 2;
        toonies = toonies++;    
        }
        
    while ( change > 1 ){
        change = change - 1;
        loonies = loonies++;
        }     
        
    while ( change > 0.25 ){
        change = change - 0.25;
        quarters = quarters++;
        }    
    
    while ( change > 0.10 ){
        change = change - 0.10;
        dimes = dimes++;
        }    
        
    while ( change > 0.05 ){
        change = change - 0.05;
        nickels = nickels++;
        }    
        
    while ( change > 0.01 ){
        change = change - 0.01;
        pennies = pennies++;
        }   
        
    if ( hundreds > 0 ){
        cout << "Number of $100 bills = " << hundreds << endl;
        }    
        
    if ( fifties > 0 ){
        cout << "Number of $50 bills = " << fifties << endl;
        }    
        
    if ( twenties > 0 ){
        cout << "Number of $20 bills = " << twenties << endl;
        }    
        
    if ( tens > 0 ){
        cout << "Number of $10 = " << tens << endl;
        }    
        
    if ( fives > 0 ){
        cout << "Number of $5 bills = " << fives << endl;
        }    
        
    if ( toonies > 0 ){
        cout << "Number of toonies = " << toonies << endl;
        }    
        
    if ( loonies > 0 ){
        cout << "Number of loonies = " << loonies << endl;
        }  
        
    if ( quarters > 0 ){
        cout << "Number of quarters = " << quarters << endl;
        }    
        
    if ( dimes > 0 ){
        cout << "Number of dimes = " << dimes << endl;
        }    
        
    if ( nickels > 0 ){
        cout << "Number of nickels = " << nickels << endl;
        }    
        
    if ( pennies > 0 ){
        cout << "Number of pennies = " << pennies << endl;
        }      
        
                     
            
    system("PAUSE");
    return EXIT_SUCCESS;
}

You should not need any while loop anymore for pennies because there is no 0.1 pennies coin! Change line 86~89 to pennies = change; and see how it works...

i compiled your code and run it .
It worked .check your input

for me it works fine, but u have to replace '>' by '>=' in all the while loops
so like if u have the change = 100, it will increase hundreds by one..

thanks ! maybe dev C++ really is outdated. i should try codeblocks::

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.