// Dick Botting. // Date: Fri Mar 31 13:03:34 PST 1995 // Modified: Wed Oct 2 14:17:43 PDT 1996 // URL: http://www.csci.csusb.edu/dick/examples/coins.cc // Source: Friedman & Koffman, pages 60-64 /* -------------Problem------------ // Determines the value of a coin collection -------------Analysis----------- See page 60 for details DATA REQUIREMENTS Inputs nickels(int) --count of nickels pennies(int) --count of pennies Outputs dollars(int) -- number of dollars she should get change(int) -- the loose change she should get Additional total_cents(int) --the total number of cents FORMULAE 1 dollar equals 100 pennies 1 nickel equals 5 pennies --------------Design------------- INITIAL ALGORITHM 1. read in counts of nickels and pennies 2. Compute the total value in cents 2.1 total_cents is 5 * nickels + pennies. 3. find value in dollars and loose change 3.1 dollars is the integer quotient of total cents and 100. 3.2 change is the remainder when total_cents is divided by 100. 4. Display the output. ------------Implementation--------- From fig2.11, page 61 ------------Alternate versions----- Programming exercise 3 on page 71 */ #include #include //defines standard things like EXIT_SUCCESS int main () { // Local data ... int pennies; // input: count of pennies int nickels; // input: count of nickels int dollars; // output: value of coins in dollars int change; // output: value of coins in cents int total_cents; // total cents represented // Read in the count of nickels and pennies. cout << "Enter the number of nickels and press return: "; cin >> nickels; cout << "Enter the number of pennies and press return: "; cin >> pennies; // Compute the total value in cents. total_cents = 5 * nickels + pennies; // Find the value in dollars and change. dollars = total_cents / 100; change = total_cents % 100; // Display the value in dollars and change. cout << "Your collection is worth " << dollars << " dollars and " << change << " cents." << endl; // Tell Operating system that all is well return EXIT_SUCCESS; }