// --------------------------------------------------------------------------- // MoneyChange.cpp // // Written By: YourNameGoesHere // Last Modified: DueDateGoesHere // // Description: // Breaks down input cent amount into appropriate change // Largest coin is 1 dollar, followed by quarters, dimes, nickels, pennies // No bills and no fifty cent pieces allowed // Breakdown uses the max amount of largest currency first // So 2345 cents cannot be represented as 2345 pennies // --------------------------------------------------------------------------- #include // include iostream to be able to use std::cin and std::cout using namespace std; // make use of the appropriate namespace for cin and cout int main() { // Pick good variable names, // comments here are for helping you, // and not really for documenting the program int cents; // Total cents entered by the user int dollars; // dollars int quarters; // quarters int dimes; // dimes int nickels; // nickels int pennies; // pennies; // Get the total cents from the user cout << "Enter total cents: "; cin >> cents; // Compute the number of each coin needed // There are several ways to do this // Computing the amount using integer division // and then subtracting it from cents repeatedly should work // Might also be able to use modulus i.e. a % b dollars = cents / 100; cents = cents - dollars*100; quarters = cents / 25; cents = cents - quarters*25; dimes = cents / 10; cents = cents - dimes*10; nickels = cents / 5; cents = cents - nickels*5; pennies = cents; // Pennies should be all that is left // Display the amounts cout << "This corresponds to " << dollars << " dollars, " << quarters << " quarters, " << dimes << " dimes, " << nickels << " nickels, and " << pennies << " pennies.\n\n"; return 0; // return 0 to indicate success to the operating system }