I am working in Borland C++ 5 and these are the specifications:
Write a program that inputs the amount of a sale and an amount tendered by a customer. The program should then calculate the total amount of change due and display the same. Then the program should calculate the individual bills and coins that would be used to give change back to a customer.
Sample output: Another example:
Amount tendered : $200.00
Amount of sale : $121.62
Your total change: $ 78.38
--------------------------------- -----------------------------------
1 fifty
1 twenty
0 tens
1 five
3 ones
0 half dollars
1 quarter
1 dime
0 nickels
3 pennies
Thanks for all your help.
Here's what I have so far:
Code:
// Program Documentation //////////////////////////////////////////////////////
//
// Project Name : CHANGE
//
// Source File : change.cpp
//
// Programmed By :Shang Fields
//
// Last Revision : 11/1/2004
//
// Version Number: 0.1
//
// Program Description ////////////////////////////////////////////////////////
//
// This program the user inputs the amount of a sale and an amount tendered
// by customer. Then the program will calculate the individual bills
// and coins that will be used to give change back to the customer.
///////////////////////////////////////////////////////////////////////////////
// Include Files //////////////////////////////////////////////////////////////
#include <iostream.h>
#include <conio.h>
// Function Prototypes ////////////////////////////////////////////////////////
// Program Mainline ///////////////////////////////////////////////////////////
int main( )
{
//-- Define a fifty,twenty,tens,five,ones,halfadollar, quarter, dime and nickel in terms of pennies.
static const unsigned PENNIES_IN_FIFTY = 50;
static const unsigned PENNIES_IN_TWENTY = 20;
static const unsigned PENNIES_IN_TENS = 10;
static const unsigned PENNIES_IN_FIVE = 5;
static const unsigned PENNIES_IN_ONES = 1;
static const unsigned PENNIES_IN_HALFDOLLARS = 50;
static const unsigned PENNIES_IN_QUQARTERS = 25;
static const unsigned PENNIES_IN_DIMES = 10;
static const unsigned PENNIES_IN_NICKELS = 5;
float total_in_cents;
float amountTendered;
float amountOfSale;
float totalChange;
//Input data
cout<<"Enter amount tendered:";
cin>>amountTendered;
cout<<"Enter amount of sale:";
cin>>amountOfSale;
cout>>totalChange;
//Calculations
fifty = total_in_cents / PENNIES_IN_FIFTY;
total_in_cents -= fifty * PENNIES_IN_FIFTY;
twenty = total_in_cents / PENNIES_IN_TWENTY;
total_in_cents -= twenty * PENNIES_IN_TWENTY;
tens = total_in_cents / PENNIES_IN_TENS;
total_in_cents -= tens * PENNIES_IN_TENS;
five = total_in_cents / PENNIES_IN_FIVE;
total_in_cents -= five * PENNIES_IN_FIVE;
ones = total_in_cents / PENNIES_IN_ONES;
total_in_cents -= ones * PENNIES_IN_ONES;
halfdollars = total_in_cents / PENNIES_IN_HALFDOLLARS;
total_in_cents -= halfdollars * PENNIES_IN_HALFDOLLARS;
quarters = total_in_cents / PENNIES_IN_QUQARTERS;
total_in_cents -= quarters * PENNIES_IN_QUQARTERS;
dimes = total_in_cents / PENNIES_IN_DIMES;
total_in_cents -= dimes * PENNIES_IN_DIMES;
nickels = total_in_cents / PENNIES_IN_NICKELS;
pennies = total_in_cents - nickels * PENNIES_IN_NICKELS;
totalChange = amountTendered - amountOfSale;
cout<<endl;
cout<< "\t\tAmount expressed in terms of change:" << endl;
cout<< "\t\t\t" << fifty << " fifty" << endl;
cout<< "\t\t\t" << twenty << " twenty" << endl;
cout<< "\t\t\t" << tens << " tens" << endl;
cout<< "\t\t\t" << five << " five" << endl;
cout<< "\t\t\t" << ones << " ones" << endl;
cout<< "\t\t\t" << halfdollars << "halfdollars" << endl;
cout<< "\t\t\t" << quarters << " quarters" << endl;
cout<< "\t\t\t" << dimes << " dimes" << endl;
cout<< "\t\t\t" << nickels << " nickels" << endl;
cout<< "\t\t\t" << pennies << " pennies" << endl<<endl;
cout<<endl;
getch();
return 0;
}//endmn
:p