1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include "stdafx.h"
//Prototype
void Change(double* money, int* bills, int* quarters, int* dimes, int* nickels, int* pennies, int* newmoney);
int _tmain(int argc, _TCHAR* argv[])
{
double money;
//Assigns pointer to hold value of money
double* pMoney = &money;
//Assigns pointers to hold the values of bills, quarters, dimes, nickels, pennies, and newmoney
int bills, quarters, dimes, nickels, pennies, newmoney;
int* pBills = &bills;
int* pQuarters = &quarters;
int* pDimes = &dimes;
int* pNickels = &nickels;
int* pPennies = &pennies;
int* pNewmoney = &newmoney;
//User Input
cout << "Please enter the amount of change to give: $";
cin >> *pMoney;
//Calls Change function and prints output
Change(pMoney, pBills, pQuarters, pDimes, pNickels, pPennies, pNewmoney);
cout << endl;
cout << "Please disperse " << bills << " - $1 bills";
cout << endl;
cout << setw(17) << *pQuarters << " - quarters";
cout << endl;
cout << setw(17) << *pDimes << " - dimes";
cout << endl;
cout << setw(17) << *pNickels << " - nickels";
cout << endl;
cout << setw(17) << *pPennies << " - pennies";
cout << endl << endl;
system("PAUSE");
return 0;
}
//Function that calculates the change based off user input
void Change(double* money, int* bills, int* quarters, int* dimes, int* nickels, int* pennies, int* newmoney)
{
*newmoney = *money * 100;
*bills = *newmoney / 100;
*newmoney = *newmoney % 100;
*quarters = *newmoney / 25;
*newmoney = *newmoney % 25;
*dimes = *newmoney / 10;
*newmoney = *newmoney % 10;
*nickels = *newmoney / 5;
*newmoney = *newmoney % 5;
*pennies = *newmoney / 1;
}
|