Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <math.h>
- using namespace std;
- int main ()
- {
- int numHundred, numTwenty, numTen, numFive, numOne, numQuarter, numTencents, numFivecents, numOnecent;
- double value;
- cout << "Insert a monetary value you would like to convert" << endl; //asks the user for a value
- cin >> value;
- while(value < 0){ //to always get a positive value
- cout << "Invalid value" << endl;
- cin >> value;
- }
- cout << "\nYour change is: " << endl; //heading
- cout << "Dollars \tNumber of Bills" << endl;
- if(value >= 100){ //if bigger than 100, say how many bills and subtract from the value
- numHundred = value / 100;
- cout << "$100 \t\t" << numHundred << endl;
- value = value - numHundred * 100;
- }
- if(value >= 20){ //if bigger than 20, say how many bills and subtract from the value
- numTwenty = value / 20;
- cout << "$20 \t\t" << numTwenty << endl;
- value = value - numTwenty * 20;
- }
- if(value >= 10){ //if bigger than 10, say how many bills and subtract from the value
- numTen = value / 10;
- cout << "$10 \t\t" << numTen << endl;
- value = value - numTen * 10;
- }
- if(value >= 5){ //if bigger than 5, say how many bills and subtract from the value
- numFive = value / 5;
- cout << "$5 \t\t" << numFive << endl;
- value = value - numFive * 5;
- }
- if(value >= 1){ //if bigger than 1, say how many bills and subtract from the value
- numOne = value / 1;
- cout << "$1 \t\t" << numOne << endl;
- value = value - numOne * 1;
- }
- if(value >= 0.25){ //if bigger than 0.25, say how many coins and subtract from the value
- numQuarter = value / 0.25;
- cout << "$0.25 \t\t" << numQuarter << endl;
- value = value - numQuarter * 0.25;
- }
- if(value >= 0.10){ //if bigger than 0.10, say how many coins and subtract from the value
- numTen = value / 0.10;
- cout << "$0.10 \t\t" << numTen << endl;
- value = value - numTen * 0.10;
- }
- if(value >= 0.05){ //if bigger than 0.05, say how many coins and subtract from the value
- numFivecents = value / 0.05;
- cout << "$0.05 \t\t" << numFivecents << endl;
- value = value - numFivecents * 0.05;
- }
- if(value >= 0.01){ //if bigger than 0.01, say how many coins and subtract from the value
- numOnecent = value / 0.01;
- cout << "$0.01 \t\t" << numOnecent << endl;
- value = value - numOnecent * 0.01;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement