All pastes #332803 Raw Edit

Unnamed

public text v1 · immutable
#332803 ·published 2007-01-30 09:05 UTC
rendered paste body
#include <iostream>
using namespace std;

// Declare constants
const double NICKEL = 0.05;
const double DIME = 0.10;
const double QUARTER = 0.25;
const double DOLLAR = 1.00;
const double TEN = 10;
const double FIFTY = 50;
const double HUNDRED = 100;

int main() 
{
	// initialize amount
	double amount = 0;
	
	// ask for input
	cout << "Enter an amount: $";
	cin >> amount;
	
	// hundred dollar bills
	int hundreds = (amount / HUNDRED);
	amount -= (hundreds * HUNDRED);
	
	// fifty dollar bills
	int fifties = (amount / FIFTY);
	amount -= (fifties * FIFTY);
	
	// ten dollar bills
	int tens = (amount / TEN);
	amount -= (tens * TEN);
	
	// dollars
	int dollars = (amount / DOLLAR);
	amount -= (dollars * DOLLAR);
	
	// quarters
	int quarters = (amount / QUARTER);
	amount -= (quarters * QUARTER);
	
	// dimes
	int dimes = (amount / DIME);
	amount -= (dimes * DIME);
	
	// nickels
	int nickels = (amount / NICKEL);
	amount -= (nickels * NICKEL);
	
	// remaining is pennies
	int pennies = amount * 100;
	
	cout << hundreds << " $100 bills" << endl
		<< fifties << " $50 bills" << endl
		<< tens << " $10 bills" << endl
		<< dollars << " $1 bills" << endl
		<< quarters << " quarters" << endl
		<< dimes << " dimes" << endl
		<< nickels << " nickels" << endl
		<< pennies << " pennies" << endl;
		
	return 0;
}