steamengines

Problem 14

Oct 2nd, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. //Christian Ballard
  2. //COSC 1330 - 003
  3. //This program should calculate and display the amount of change owed.
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     //Variables
  11.     double moneyOwe = 0.0;
  12.     double moneyPaid = 0.0;
  13.     double change = 0.0;
  14.     int dollars = 100;
  15.     int dollarsReturn = 0;
  16.     int quarters = 25;
  17.     int quartersReturn = 0;
  18.     int dimes = 10;
  19.     int dimesReturn = 0;
  20.     int nickels = 5;
  21.     int nickelsReturn = 0;
  22.     int pennies = 1;
  23.     int penniesReturn = 0;
  24.     int changeInPennies = 0;
  25.  
  26.  
  27.     //input
  28.     cout << "Enter the amount owed" << endl;
  29.     cin >> moneyOwe;
  30.     cout << "Enter the amount paid" << endl;
  31.     cin >> moneyPaid;
  32.  
  33.  
  34.     //Calculations
  35.  
  36.     change = (moneyPaid - moneyOwe);
  37.     changeInPennies = (change * 100);
  38.  
  39.  
  40.  
  41.     if (moneyPaid < moneyOwe)
  42.     {
  43.         cout << "You are missing $" << (moneyOwe - moneyPaid) << endl;
  44.     }
  45.     else
  46.     {
  47.         dollarsReturn = (changeInPennies / dollars);
  48.         quartersReturn = (changeInPennies % dollars) / quarters;
  49.         dimesReturn = (changeInPennies % dollars % quarters) / dimes;
  50.         nickelsReturn = (changeInPennies % dollars % quarters % dimes) / nickels;
  51.         penniesReturn = (changeInPennies % dollars % quarters % dimes % nickels) / pennies;
  52.     }
  53.    
  54.     //Output
  55.     cout << "Your total change is " << change << endl;
  56.     cout << "Dollars owed " << dollarsReturn << endl;
  57.     cout << "Quarters owed " << quartersReturn << endl;
  58.     cout << "Dimes owed " << dimesReturn << endl;
  59.     cout << "Nickels owed " << nickelsReturn << endl;
  60.     cout << "Pennies owed " << penniesReturn << endl;
  61.  
  62.     system("pause");
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment