Advertisement
KevinNT03

Change Calculator

Mar 7th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8.     int numHundred, numTwenty, numTen, numFive, numOne, numQuarter, numTencents, numFivecents, numOnecent;
  9.     double value;
  10.    
  11.     cout << "Insert a monetary value you would like to convert" << endl; //asks the user for a value
  12.     cin >> value;
  13.     while(value < 0){ //to always get a positive value
  14.         cout << "Invalid value" << endl;
  15.         cin >> value;
  16.     }
  17.    
  18.     cout << "\nYour change is: " << endl; //heading
  19.     cout << "Dollars \tNumber of Bills" << endl;
  20.    
  21.     if(value >= 100){ //if bigger than 100, say how many bills and subtract from the value
  22.         numHundred = value / 100;
  23.         cout << "$100 \t\t" << numHundred << endl;
  24.         value = value - numHundred * 100;
  25.     }
  26.     if(value >= 20){ //if bigger than 20, say how many bills and subtract from the value
  27.         numTwenty = value / 20;
  28.         cout << "$20  \t\t" << numTwenty << endl;
  29.         value = value - numTwenty * 20;
  30.     }
  31.     if(value >= 10){ //if bigger than 10, say how many bills and subtract from the value
  32.         numTen = value / 10;
  33.         cout << "$10  \t\t" << numTen << endl;
  34.         value = value - numTen * 10;
  35.     }
  36.     if(value >= 5){ //if bigger than 5, say how many bills and subtract from the value
  37.         numFive = value / 5;
  38.         cout << "$5   \t\t" << numFive << endl;
  39.         value = value - numFive * 5;
  40.     }
  41.     if(value >= 1){ //if bigger than 1, say how many bills and subtract from the value
  42.         numOne = value / 1;
  43.         cout << "$1   \t\t" << numOne << endl;
  44.         value = value - numOne * 1;
  45.     }
  46.     if(value >= 0.25){ //if bigger than 0.25, say how many coins and subtract from the value
  47.         numQuarter = value / 0.25;
  48.         cout << "$0.25 \t\t" << numQuarter << endl;
  49.         value = value - numQuarter * 0.25;
  50.     }
  51.     if(value >= 0.10){ //if bigger than 0.10, say how many coins and subtract from the value
  52.         numTen = value / 0.10;
  53.         cout << "$0.10 \t\t" << numTen << endl;
  54.         value = value - numTen * 0.10;
  55.     }
  56.     if(value >= 0.05){ //if bigger than 0.05, say how many coins and subtract from the value
  57.         numFivecents = value / 0.05;
  58.         cout << "$0.05 \t\t" << numFivecents << endl;
  59.         value = value - numFivecents * 0.05;
  60.     }
  61.     if(value >= 0.01){ //if bigger than 0.01, say how many coins and subtract from the value
  62.         numOnecent = value / 0.01;
  63.         cout << "$0.01 \t\t" << numOnecent << endl;
  64.         value = value - numOnecent * 0.01;
  65.     }
  66.    
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement