# Thread: Can someone explain how this function works?

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