954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

homework help

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;
}
networkZombie
Newbie Poster
12 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

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...

Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
 

Its still not working :(

networkZombie
Newbie Poster
12 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

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

alaa sam
Junior Poster
135 posts since Nov 2010
Reputation Points: 8
Solved Threads: 10
 

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..

low_coder
Junior Poster in Training
55 posts since Nov 2008
Reputation Points: 40
Solved Threads: 4
 

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

networkZombie
Newbie Poster
12 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: