"Internationalisation with PHP and Intl" source code
capstoneCMPSC101
1. // Richard Rafalko Jr.
// Capstone Project for Change Due Customer
// November 16, 2014
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <cstring>
using namespace std;
//Function prototype declarations
void moreMoney(double cash, double sale);
void printChange(double cash, double sale, double &changeDue);
int moneyConvert(double changeDue);
void calcChangeDue(int change);
void error();
void spacer();
int _tmain(int argc, _TCHAR* argv[])
{
double sale = 0.0;
double cash = 0.0;
double changeDue = 0.0;
int change = 0;
//Asks for sale amount and cash tendered
cout << "Amount of Sale: $";
cin >> sale;
cout << endl << "Amount tendered: $";
cin >> cash;
spacer();
//Checks for cash payment and sale equivalence
if (cash == sale)
{
cout << "There is no change."; spacer();
}
//Checks to see if payment was less than owed
else if (sale > cash)
moreMoney(cash, sale);
/*Checks to see if payment was more than owed. If so,
then 3 function calls for calculating change.*/
else if (sale < cash)
{
printChange(cash, sale, changeDue); //prints out the change due
change = moneyConvert(changeDue); //returns integer units for denoms
calcChangeDue(change); //main function for finding each denom
}
2. //For invalid data entry
else
{
error();
}
system("pause");
return 0;
}
//******************************************
//FUNCTIONS FOR CALCULATIONS AND CONVERSIONS
//******************************************
//Prints out when user still owes money
void moreMoney(double cash, double sale)
{
cout << "You still owe $" << sale - cash; spacer();
}
//Prints out the precise amount of money that is owed.
void printChange(double cash, double sale, double &changeDue)
{
changeDue = cash - sale;
cout << "The change is ... $" << fixed << setprecision(2) << changeDue; spacer();
}
//Converts double value, retuns integer units
int moneyConvert(double change)
{
return((change + .00000001) * 100); //The addition here adds precision
}
//****************************************************************
//MAIN FUNCTION THAT FINDS DENOMINATION UNITS AND PRINTS THE UNITS
//****************************************************************
void calcChangeDue(int change)
{
int breakdown[8] = { 0 };
string singleDenoms[8] = { " twenty dollar bill", " ten dollar bill",
" five dollar bill", " one dollar bill", " quarter",
" dime", " nickel", " penny" };
string multipleDenoms[8] = { " twenty dollar bills", " ten dollar bills",
" five dollar bills", " one dollar bills", " quarters",
" dimes", " nickels", " pennies" };
//Calculates the amount of each denomination of bills and coin for return to customer in units
breakdown[0] = change / 2000; change = change - (breakdown[0] * 2000);
breakdown[1] = change / 1000; change = change - (breakdown[1] * 1000);
breakdown[2] = change / 500; change = change - (breakdown[2] * 500);
breakdown[3] = change / 100; change = change - (breakdown[3] * 100);
3. breakdown[4] = change / 25; change = change - (breakdown[4] * 25);
breakdown[5] = change / 10; change = change - (breakdown[5] * 10);
breakdown[6] = change / 5; change = change - (breakdown[6] * 5);
breakdown[7] = change / 1; change = change - (breakdown[7] * 1);
//Loop for printing out exactly what is owed. Loop does not print out when array quadrant is null.
for (int x = 0; x < 8; x++)
{
if (breakdown[x] == 1)
{
cout << breakdown[x] << singleDenoms[x] << endl;
}
else if (breakdown[x] > 1)
{
cout << breakdown[x] << multipleDenoms[x] << endl;
}
}
spacer();
}
//Failsafe for improper data entry
void error()
{
cout << "Improper data entered."; spacer();
}
//Quick function for spacing on output
void spacer()
{
cout << endl << endl;
}