still not working... whenever i enter .05, .10, or .25 cents it doesn't work. it will work for pennies and also all the dollars.
Code:
// ***********************************************************
// Program Make Change: Given any amount of change expressed
// in cents, this program computes the number of half-dollars,
// quarters, dimes, nickels, and pennies to be returned,
// returning as many half-dollars as possible, then quarters,
// dimes, nickels, and pennies in that order.
//************************************************************
//header file
#include <iostream>
using namespace std;
//named constants
void convertChange(int change, int& nquarter, int& ndime, int& nnickel, int& nonedollar,
int& nfivedollar, int& ntendollar, int& ntwentydollar, int& npennies);
int main()
{
int nnickel = 0;
int ndime = 0;
int nquarter = 0;
int nonedollar = 0;
int nfivedollar = 0;
int ntendollar = 0;
int ntwentydollar = 0;
int npennies = 0;
//declare variable
int change;
double changeone;
//Statements: Step 1 - Step 12
cout << "Enter change in decimal value: "; //Ask user for change in decimal value
cin >> changeone; //Input change
cout << endl;
cout << "The change you entered is " << changeone
<< endl; //Output entered change
change = changeone * 100;
convertChange(change, nnickel, ndime, nquarter, nonedollar, nfivedollar, ntendollar, ntwentydollar, npennies);
//cout << "The number of 20 dollars to be returned is ";
//<< change / twentydollar << endl;
//change = change % twentydollar;
//cout << "The number of 10 dollars to be returned is ";
//<< change / tendollar << endl;
//change = change % tendollar;
//cout << "The number of 5 dollars to be returned is ";
//<< change / fivedollar << endl;
//change = change % fivedollar;
//cout << "The number of 1 dollars to be returned is ";
//<< change / onedollar << endl;
//change = change % onedollar;
//cout << "The number of half-dollars to be returned "
//<< "is " << change / Halfdollar
//<< endl; //Perform integer division to find number of half-dollars to be returned.
//change = change % Halfdollar; //Remove change from larger value.
//cout << "The number of quarters to be returned is ";
//<< change / Quarter << endl; //Perform integer division to find number of quarters to be returned.
//change = change % Quarter; //Remove change from larger value.
//cout << "The number of dimes to be returned is ";
//<< change / Dime << endl; //Perform integer division to find number of dimes to be returned.
//change = change % Dime; //Remove change from larger value.
//cout << "The number of nickels to be returned is ";
//<< change / Nickel << endl; //Perform integer division to find number of nickels to be returned.
//change = change % Nickel; //Remove change from larger value.
//cout << "The number of pennies to be returned is ";
//<< change << endl; //Use remaining change to find number of pennies.
//output statements
cout << "The number of pennies to be returned is " << npennies << endl;
cout << "The number of nickels to be returned is " << nnickel << endl;
cout << "The number of dimes to be returned is " << ndime << endl;
cout << "The number of quarters to be returned is " << nquarter << endl;
cout << "The number of 1 dollars to be returned is " << nonedollar << endl;
cout << "The number of 5 dollars to be returned is " << nfivedollar << endl;
cout << "The number of 10 dollars to be returned is " << ntendollar << endl;
cout << "The number of 20 dollars to be returned is " << ntwentydollar << endl;
return 0;
}
void convertChange(int change, int& nquarter, int& ndime, int& nnickel, int& nonedollar,
int& nfivedollar, int& ntendollar, int& ntwentydollar, int& npennies)
{
const int Nickel = 5;
const int Dime = 10;
const int Quarter = 25;
const int onedollar = 100;
const int fivedollar = 500;
const int tendollar = 1000;
const int twentydollar = 2000;
ntwentydollar = change / twentydollar;
change = change % twentydollar;
ntendollar = change / tendollar;
change = change % tendollar;
nfivedollar = change / fivedollar;
change = change % fivedollar;
nonedollar = change / onedollar;
change = change % onedollar;
nquarter = change / Quarter;
change = change % Quarter;
ndime = change / Dime;
change = change % Dime;
nnickel = change / Nickel;
change = change % Nickel;
npennies = change;
}