//So I'm writing this program that converts change into smaller denominations. 
//For example .97 would be 3 quarters, 2 dimes, 0 nickels, with 2 remaining. 
//The program compiles and runs but it's not the completely correct output. Can //anyone help.
//Converts change into small denominations.

#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
	int quarters = .25;
	int dimes = .10;
	int nickels = .05;
	int pennies = .01;
	double usersMoney;
	cout << "Enter a decimal for change amount";
	cin >> usersMoney;
	int amount = (usersMoney / .25);
	int remaining = usersMoney - (amount * .25);
	int amount1 = (remaining / .10);
	int remaining1 = remaining - (amount1 * .10);
	int amount2 = (remaining1 / .05);
	int remaining2 = remaining1 - (amount2 * .05);
	cout << usersMoney << " converted is: " << amount << " quarters " << amount1 << " dimes " << amount2 << " nickels. With " << remaining2 << " remaining." << endl;
    getch();
    return 0;
}

Recommended Answers

All 2 Replies

Well for starters an int can not hold decimals. A float or a double is required for that. you can do this with int's if you know how to use the % operator.

I would use a loop for each denomination of coin. I would subtract the value of each coin from the remainder each time through each loop and I would increment the number of each coin appropriately each time through a loop. I don't see how division or modulus will give the number of each coin otherwise.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.