//Sam Partovi CS1A Chapter 4, P. 221, #8
//
/*******************************************************************************
*
* SIMULATE COIN COUNTING GAME
* ____________________________________________________________
* This program simulates a coin counting game where the defined quantities of
* coins including pennies, nickels, dimes, and quarters must equal a specific
* dollar amount.
*
* The simulation is based on the following analysis:
* If the value of each coin multiplied by the quantity of each coin is equal to
* the specified dollar amount, the player wins the game.
* ____________________________________________________________
*INPUT
* pennyQuantity : Player's quantity of pennies
* nickelQuantity : Player's quantity of nickels
* dimeQuantity : Player's quantity of dimes
* quarterQuantity : Player's quantity of quarters
* pennyValue : Monetary value held by one penny
* nickelValue : Monetary value held by one nickel
* dimeValue : Monetary value held by one dime
* quarterValue : Monetary value held by one quarter
* dollarGoal : Goal dollar amount to be counted
*
*OUTPUT
* coinTotal : Total value of all coins entered
******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int pennyQuantity; //INPUT - Player's quantity of pennies
int nickelQuantity; //INPUT - Player's quantity of nickels
int dimeQuantity; //INPUT - Player's quantity of dimes
int quarterQuantity; //INPUT - Player's quantity of quarters
float dollarGoal; //INPUT - Goal dollar amount to be counted
float coinTotal; //OUTPUT - Total value of all coins entered
//Initialize program variables
const float pennyValue = 0.01; //INPUT - Monetary value held by one penny
const float nickelValue = 0.05; //INPUT - Monetary value held by one nickel
const float dimeValue = 0.10; //INPUT - Monetary value held by one dime
const float quarterValue = 0.25; //INPUT - Monetary value held by one quarter
dollarGoal = 1.00;
//Format output to 2 decimal places
cout << fixed << setprecision(2);
//Prompt player for coin quantities
cout << "Coin counting game\n";
cout << "___________________\n";
cout << "Your goal is to count enough coins to make $" << dollarGoal << ".\n";
cout << "Enter number of pennies: ";
cin >> pennyQuantity;
cout << "\nEnter number of nickels: ";
cin >> nickelQuantity;
cout << "\nEnter number of dimes: ";
cin >> dimeQuantity;
cout << "\nEnter number of quarters: ";
cin >> quarterQuantity;
//Perform coin total value calculation
coinTotal = (pennyQuantity * pennyValue) + (nickelQuantity * nickelValue)
+ (dimeQuantity * dimeValue) + (quarterQuantity * quarterValue);
//Determine if player has won or lost the game
if (coinTotal == dollarGoal) {
cout << "\nCongratulations! You counted out $" << coinTotal << ".";
}
else {
cout << "\nTry again! You entered $" << coinTotal << ".\n";
}
return 0;
}