I have been building a very basic program to convert dollars and change to coins. This program is similar to an example in the book I am using. I try to make small changes to ensure that I understand the concepts of the program. I am having success at converting the input of dollars and cents into all cents, and the proper number of quarters displays. Regardless of input, quarters is correct, dimes shows 1, nickels and pennies produces 0. Looking at the book example (I tried to build before cheating with example) my code appears accurate but the results do not work. I have compiled the code in Visual Studio 2010 and CodeBlocks v 10.05.
Code:
#include <iostream>
//This program makes change in quarters, dimes, nickles, and pennies
using namespace std;
int main()
{
int cents, dollars, total, quarters, dimes, nickels, pennies; //named variables
quarters = 25, dimes = 10, nickels = 5, pennies = 1; //establishing vaLues for variables
cout << "This program will report change due/n"
<< "using the minimum number of coins." << endl;
cout << "Enter number of dollars. " << endl;
cin >> dollars; //user input
cin.ignore();
cout << "You entered " << dollars << "." //output of user input
<< " Now enter the amount of change." << endl; //user input
cin >> cents;
cin.ignore();
cout << "You entered " << cents << "." << endl; //output of user input
total = dollars * 100 + cents; //converts dollars to cents and adds cents
cout << "Your total is " << total << "cents" << endl; //total of input converted to cents
total = total / quarters; //divide by 25 to determine # of quarters
cout << "You receive" << total << "quarters." << endl; //output of quarters
total = total % quarters; //remainder of cents
total = total / dimes; //divide by 10 to determine # of dimes
cout << "You receive" << total << "dimes." << endl; //output of dimes
total = total % dimes; //remainder of cents
total = total / nickels; //divide by 5 to determine # of nickels
cout << "You receive" << total << "nickels." << endl; //output of nickels
total = total % nickels; //remainder of cents
total = total / pennies; //divide by 1 to determine # of pennies
cout << "You receive" << total << "pennies." << endl; //output of pennies
cout << "Press the Enter key to close." << endl; //keeps program open to view until Enter key is pressed
cin.get();
return 0;
}
I would appreciate a clue as to where I am making my code error(s).
Thank you