Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Christian Ballard
- //COSC 1330 - 003
- //This program should calculate and display the amount of change owed.
- #include <iostream>
- using namespace std;
- int main()
- {
- //Variables
- double moneyOwe = 0.0;
- double moneyPaid = 0.0;
- double change = 0.0;
- int dollars = 100;
- int dollarsReturn = 0;
- int quarters = 25;
- int quartersReturn = 0;
- int dimes = 10;
- int dimesReturn = 0;
- int nickels = 5;
- int nickelsReturn = 0;
- int pennies = 1;
- int penniesReturn = 0;
- int changeInPennies = 0;
- //input
- cout << "Enter the amount owed" << endl;
- cin >> moneyOwe;
- cout << "Enter the amount paid" << endl;
- cin >> moneyPaid;
- //Calculations
- change = (moneyPaid - moneyOwe);
- changeInPennies = (change * 100);
- if (moneyPaid < moneyOwe)
- {
- cout << "You are missing $" << (moneyOwe - moneyPaid) << endl;
- }
- else
- {
- dollarsReturn = (changeInPennies / dollars);
- quartersReturn = (changeInPennies % dollars) / quarters;
- dimesReturn = (changeInPennies % dollars % quarters) / dimes;
- nickelsReturn = (changeInPennies % dollars % quarters % dimes) / nickels;
- penniesReturn = (changeInPennies % dollars % quarters % dimes % nickels) / pennies;
- }
- //Output
- cout << "Your total change is " << change << endl;
- cout << "Dollars owed " << dollarsReturn << endl;
- cout << "Quarters owed " << quartersReturn << endl;
- cout << "Dimes owed " << dimesReturn << endl;
- cout << "Nickels owed " << nickelsReturn << endl;
- cout << "Pennies owed " << penniesReturn << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment