Can someone explain how this function works?

This is a discussion on Can someone explain how this function works? within the C++ Programming forums, part of the General Programming Boards category; outputLine(countForDenom1(amountLeftToChange),deno mName1); In this code #include<iostream.h> void inputInt(int& aNumber, const char prompt[]); void outputLine(int aNumber, const char aString[]); void divMod(int ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    84

    Can someone explain how this function works?

    outputLine(countForDenom1(amountLeftToChange),deno mName1);

    In this code
    #include<iostream.h>

    void inputInt(int& aNumber, const char prompt[]);

    void outputLine(int aNumber, const char aString[]);

    void divMod(int numerator, int denominator, int& quotient, int& remainder);

    int countForDenom1(int& amountLeft);
    int countForDenom2(int& amountLeft);
    int countForDenom3(int& amountLeft);
    int countForDenom4(int& amountLeft);
    int countForDenom5(int& amountLeft);
    int countForDenom6(int& amountLeft);
    int countForDenom7(int& amountLeft);
    int countForDenom8(int& amountLeft);

    const int denomValue1 = 2000;
    const char denomName1[] = "twenties";
    const int denomValue2 = 1000;
    const char denomName2[] = "tens";
    const int denomValue3 = 500;
    const char denomName3[] = "fives";
    const int denomValue4 = 100;
    const char denomName4[] = "ones";
    const int denomValue5 = 25;
    const char denomName5[] = "quarters";
    const int denomValue6 = 10;
    const char denomName6[] = "dimes";
    const int denomValue7 = 5;
    const char denomName7[] = "nickels";
    const int denomValue8 = 1;
    const char denomName8[] = "pennies";

    void main()
    {
    cout<< "Change Maker (version)2)\n\n";

    int amountLeftToChange;

    inputInt(amountLeftToChange, "Enter amount to be changed in pennies: ");


    outputLine(countForDenom1(amountLeftToChange),deno mName1);
    outputLine(countForDenom2(amountLeftToChange),deno mName2);
    outputLine(countForDenom3(amountLeftToChange),deno mName3);
    outputLine(countForDenom4(amountLeftToChange),deno mName4);
    outputLine(countForDenom5(amountLeftToChange),deno mName5);
    outputLine(countForDenom6(amountLeftToChange),deno mName6);
    outputLine(countForDenom7(amountLeftToChange),deno mName7);
    outputLine(countForDenom8(amountLeftToChange),deno mName8);

    }
    //////////////////////////////////////////////////////////////////////
    void inputInt(int& aNumber, const char prompt[])
    {
    cout<<prompt<<endl;
    cin>>aNumber;
    }
    //////////////////////////////////////////////////////////////////////
    void outputLine(int aNumber, const char aString[])
    {
    cout<<aNumber<<" "<<aString<<endl;
    }
    //////////////////////////////////////////////////////////////////////
    void divMod(int numerator, int denominator, int& quotient, int& remainder)
    {
    quotient = numerator/denominator;
    remainder = numerator % denominator;
    }
    ///////////////////////////////////////////////////////////////////////
    int countForDenom1(int& amountLeft)
    {
    int result;
    divMod(amountLeft,denomValue1, result, amountLeft);
    return result;
    }
    ///////////////////////////////////////////////////////////////////////
    int countForDenom2(int& amountLeft)
    {
    int result;
    divMod(amountLeft,denomValue2, result, amountLeft);
    return result;
    }
    ///////////////////////////////////////////////////////////////////////
    int countForDenom3(int& amountLeft)
    {
    int result;
    divMod(amountLeft,denomValue3, result, amountLeft);
    return result;
    }
    ///////////////////////////////////////////////////////////////////////
    int countForDenom4(int& amountLeft)
    {
    int result;
    divMod(amountLeft,denomValue4, result, amountLeft);
    return result;
    }
    ///////////////////////////////////////////////////////////////////////
    int countForDenom5(int& amountLeft)
    {
    int result;
    divMod(amountLeft,denomValue5, result, amountLeft);
    return result;
    }
    ///////////////////////////////////////////////////////////////////////
    int countForDenom6(int& amountLeft)
    {
    int result;
    divMod(amountLeft,denomValue6, result, amountLeft);
    return result;
    }
    ///////////////////////////////////////////////////////////////////////
    int countForDenom7(int& amountLeft)
    {
    int result;
    divMod(amountLeft,denomValue7, result, amountLeft);
    return result;
    }
    ///////////////////////////////////////////////////////////////////////
    int countForDenom8(int& amountLeft)
    {
    int result;
    divMod(amountLeft,denomValue8, result, amountLeft);
    return result;
    }
    ///////////////////////////////////////////////////////////////////////

  2. #2
    Unregistered
    Guest
    it takes the int returned by a function of generic type countForDenomX() and the string associated with that denomination represented by denomNameX and prints the values to the screen.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  3. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  4. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21