SlideShare a Scribd company logo
1 of 3
// 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
}
//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);
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;
}

More Related Content

What's hot

Documentadsbyadbrite1
Documentadsbyadbrite1Documentadsbyadbrite1
Documentadsbyadbrite1girdhar gopal
 
Documentadsbyadbrite2
Documentadsbyadbrite2Documentadsbyadbrite2
Documentadsbyadbrite2girdhar gopal
 
14. CodeIgniter adaugarea inregistrarilor
14. CodeIgniter adaugarea inregistrarilor14. CodeIgniter adaugarea inregistrarilor
14. CodeIgniter adaugarea inregistrarilorRazvan Raducanu, PhD
 
Webit expo Standard Product
Webit expo Standard ProductWebit expo Standard Product
Webit expo Standard ProductBoji Ditcheva
 
Inheritance and polymorphism
Inheritance and polymorphismInheritance and polymorphism
Inheritance and polymorphismmohamed sikander
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboardsDenis Ristic
 
Windows Phone 8 Sensors
Windows Phone 8 SensorsWindows Phone 8 Sensors
Windows Phone 8 SensorsDavid Isbitski
 
Declaring friend function with inline code
Declaring friend function with inline codeDeclaring friend function with inline code
Declaring friend function with inline codeRajeev Sharan
 
06 jQuery #burningkeyboards
06 jQuery  #burningkeyboards06 jQuery  #burningkeyboards
06 jQuery #burningkeyboardsDenis Ristic
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd marchRajeev Sharan
 

What's hot (12)

Documentadsbyadbrite1
Documentadsbyadbrite1Documentadsbyadbrite1
Documentadsbyadbrite1
 
Documentadsbyadbrite2
Documentadsbyadbrite2Documentadsbyadbrite2
Documentadsbyadbrite2
 
14. CodeIgniter adaugarea inregistrarilor
14. CodeIgniter adaugarea inregistrarilor14. CodeIgniter adaugarea inregistrarilor
14. CodeIgniter adaugarea inregistrarilor
 
Webit expo Standard Product
Webit expo Standard ProductWebit expo Standard Product
Webit expo Standard Product
 
Inheritance and polymorphism
Inheritance and polymorphismInheritance and polymorphism
Inheritance and polymorphism
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
 
Windows Phone 8 Sensors
Windows Phone 8 SensorsWindows Phone 8 Sensors
Windows Phone 8 Sensors
 
Declaring friend function with inline code
Declaring friend function with inline codeDeclaring friend function with inline code
Declaring friend function with inline code
 
5. hello popescu
5. hello popescu5. hello popescu
5. hello popescu
 
06 jQuery #burningkeyboards
06 jQuery  #burningkeyboards06 jQuery  #burningkeyboards
06 jQuery #burningkeyboards
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd march
 
Migrare da symfony 1 a Symfony2
 Migrare da symfony 1 a Symfony2  Migrare da symfony 1 a Symfony2
Migrare da symfony 1 a Symfony2
 

Viewers also liked

Cambodia budget allocation
Cambodia budget allocationCambodia budget allocation
Cambodia budget allocationvibol dong
 
Presentacion introduccion al derecho
Presentacion introduccion al derechoPresentacion introduccion al derecho
Presentacion introduccion al derechoPeter Mogollon
 
Test de mantenimiento del pc
Test de mantenimiento del pcTest de mantenimiento del pc
Test de mantenimiento del pcadrianachapal
 
8 simple steps to creating a great presentation
8 simple steps to creating a great presentation8 simple steps to creating a great presentation
8 simple steps to creating a great presentationdanielchingbrandman
 
Presentation book review
Presentation book reviewPresentation book review
Presentation book reviewOfer Ashtamkar
 
8 simple steps to delivering a great presentation
8 simple steps to delivering a great presentation8 simple steps to delivering a great presentation
8 simple steps to delivering a great presentationdanielchingbrandman
 

Viewers also liked (10)

Cambodia budget allocation
Cambodia budget allocationCambodia budget allocation
Cambodia budget allocation
 
Presentacion introduccion al derecho
Presentacion introduccion al derechoPresentacion introduccion al derecho
Presentacion introduccion al derecho
 
Test de mantenimiento del pc
Test de mantenimiento del pcTest de mantenimiento del pc
Test de mantenimiento del pc
 
8 simple steps to creating a great presentation
8 simple steps to creating a great presentation8 simple steps to creating a great presentation
8 simple steps to creating a great presentation
 
Dizajn manuál_Rádio YES
Dizajn manuál_Rádio YESDizajn manuál_Rádio YES
Dizajn manuál_Rádio YES
 
Our Shadow Presentation
Our Shadow PresentationOur Shadow Presentation
Our Shadow Presentation
 
limbs brochure
limbs brochurelimbs brochure
limbs brochure
 
Presentation book review
Presentation book reviewPresentation book review
Presentation book review
 
8 simple steps to delivering a great presentation
8 simple steps to delivering a great presentation8 simple steps to delivering a great presentation
8 simple steps to delivering a great presentation
 
Farmakognosi
FarmakognosiFarmakognosi
Farmakognosi
 

Similar to capstoneCMPSC101

c++ project on restaurant billing
c++ project on restaurant billing c++ project on restaurant billing
c++ project on restaurant billing Swakriti Rathore
 
Mdp plus 2.1
Mdp plus 2.1Mdp plus 2.1
Mdp plus 2.1boedax
 
This what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdfThis what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdfkavithaarp
 
Pointers in c++ programming presentation
Pointers in c++ programming presentationPointers in c++ programming presentation
Pointers in c++ programming presentationSourabhGour9
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuningAOE
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyGrejoJoby1
 
The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196Mahmoud Samir Fayed
 
Arduino based keyboard and display interfacing
Arduino based keyboard and display interfacingArduino based keyboard and display interfacing
Arduino based keyboard and display interfacingAkash1900
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuningAOE
 
The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184Mahmoud Samir Fayed
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxssuser454af01
 
"Internationalisation with PHP and Intl" source code
"Internationalisation with PHP and Intl" source code"Internationalisation with PHP and Intl" source code
"Internationalisation with PHP and Intl" source codeDaniel_Rhodes
 

Similar to capstoneCMPSC101 (20)

c++ project on restaurant billing
c++ project on restaurant billing c++ project on restaurant billing
c++ project on restaurant billing
 
DataTypes.ppt
DataTypes.pptDataTypes.ppt
DataTypes.ppt
 
Mdp plus 2.1
Mdp plus 2.1Mdp plus 2.1
Mdp plus 2.1
 
Marcus Portfolio
Marcus  PortfolioMarcus  Portfolio
Marcus Portfolio
 
This what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdfThis what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdf
 
Pointers in c++ programming presentation
Pointers in c++ programming presentationPointers in c++ programming presentation
Pointers in c++ programming presentation
 
Oop1
Oop1Oop1
Oop1
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
Day 1
Day 1Day 1
Day 1
 
The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196
 
Arduino based keyboard and display interfacing
Arduino based keyboard and display interfacingArduino based keyboard and display interfacing
Arduino based keyboard and display interfacing
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
 
The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184
 
project
projectproject
project
 
SQL Server 2008 Portfolio
SQL Server 2008 PortfolioSQL Server 2008 Portfolio
SQL Server 2008 Portfolio
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
 
Cpp
Cpp Cpp
Cpp
 
Algo
AlgoAlgo
Algo
 
"Internationalisation with PHP and Intl" source code
"Internationalisation with PHP and Intl" source code"Internationalisation with PHP and Intl" source code
"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; }