Thread: Need Help Please

  1. #1
    dumberer1
    Guest

    Need Help Please

    If someone could help me out i would be really thankful.
    Code:
    #include <iostream.h>
    void main ()
    {
    
    int quarter, dime, nickel, penny, change;
    int remainderq, remainderd, remaindern;
    cout <<"This is a program that calculates the number of quarters, dimes, nickels,\nand pennies necessary to generate the number of cents entered as input.\n"; 
    cout <<"Enter the amount of change to be calculated->";
    cin >> change;
    
    quarter = change / 25;
    
    q = change % 25;
    
    dime = q / 10;
    
    d = dime % 5;
    
    nickel = d / 5;
    
    cout <<;
    }
    I'm confused.

  2. #2
    dumberer1
    Guest

    UPDATE

    updated version
    Code:
    #include <iostream.h>
    void main ()
    {
    
    int quarter, dime, nickel, penny, change;
    int remainderq, remainderd, remaindern;
    cout <<"This is a program that calculates the number of quarters, dimes, nickels,\nand pennies necessary to generate the number of cents entered as input.\n"; 
    cout <<"Enter the amount of change to be calculated->";
    cin >> change;
    
    quarter = change / 25;
    
    remainderq = change % 25;
    
    dime = remainderq / 10;
    
    remainderd = remainderq % 10;
    
    nickel = remainderd / 5;
    
    remaindern = remainderd % 5;
    
    penny = remaindern / 1;
    cout << quarter;
    cout << dime;
    cout << nickel;
    cout << penny;
    
    }
    Is there a way i can make it easier???

  3. #3
    dumberer1
    Guest

    Talking im so proud

    Well i figured it out on my own. So i guess i didnt need any help

  4. #4
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    > Is there a way i can make it easier???

    Maybe more compact:
    Code:
    #include <iostream>
    
    int calc(const char *coin, int money, int value)
    {
       cout << coin << ": " << money / value << "\n";
       return money % value;
    }
    
    int main(void)
    {
       int money;
    
       cout << "Enter the amount of change to be calculated-> ";
       cin >> money;
    
       calc("cents", calc("nickels", calc("dimes", calc("quarters", money, 25), 10), 5), 1);
    }

Popular pages Recent additions subscribe to a feed