0
//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;
}

Edited by WaltP: Added CODE Tags -- please use them

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Lerner
0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.