/* In-class #5: Write a C++ program that converts between money value and its co
ID: 3616538 • Letter: #
Question
/*
In-class #5:
Write a C++ program that converts between money value and its coin equivalence.
If coin to money is desired, it asks for coin value and converts them to money value;
Otherwise, if money to coin is desired, it asks for money value and converts to its
coin equivalence. Coin type is limited to quarter, dime, nickel, and penny. And
coin equivalence is restricted to the least amount of coins. Use setw to format the output
as shown in the sample output.
Note:
Input/output is listed as coin to money. For money to coin, just flip input and output
INPUT INFO conversion type - c for coin to money, m for money to coin
number of quarters - numQ - no decimal
number of dime, - numD - no decimal
number of nickes - numN - no decimal
number of pennies - numP - no decimal
OUTPUT INFO money value, in dollar - moneyValue - real number
CONSTANTS as cents: QUARTER = 25
DIME = 10
NICKEL = 5
DOLLAR = 100
CONSTRAINTS 1. coin equivalence to be the least amount of coins
2. format the output as a chart as following:
Coin Money Conversion
Moneytary Amount Dollar(s) Quarter(s) Dime(s) Nickel(s) Penny(s)
1.33 1 1 0 1 3
OPERATIONS
1. Display a menu to get user choice: c for coin to money, m for money to coin
2. Get user choice
3. If user chooses m then
3a. Prompt and get money value
3b. Determine number of dollar bills --- you figure out how
3c. convert left over to total pennies, as int, round off --- you figure out how
3d. numQ is integral part of totalPenny / QUARTER
3e. remainder = totalPenny - numQ * QUARTER
3f. numD is integral part of remainder / DIME
3g. remainder = remainder - numD * DIME
3h. numN = remainder / NICKEL
3i. numP = left over after nickel
4. Else if user choose c then
--- you fill up the steps
5. Either way, display the result
*/
#include
#include
using
// global constants are declared above main
const
DIME = 10,
NICKEL = 5,
DOLLAR = 100;
int
{
numD,
numN,
numP,
remainder,
totalPenny,
dollars;
cout <<
<<
<<
<<
cin >> type;
{
cout <<
cin >> moneyValue;
dollars =
numQ = totalPenny / QUARTER;
remainder = totalPenny % QUARTER;
numD = remainder / DIME;
remainder %= DIME;
numN = remainder / NICKEL;
numP = remainder % NICKEL;
}
{
}
system(
}
Explanation / Answer
please rate - thanks #include #include using namespace std; // global constants are declared above main const int QUARTER = 25, DIME = 10, NICKEL = 5, DOLLAR = 100; int main() { // items in input and output are declared as variables // variables are declared within a function char type; // for conversion type, c for coin to money, m for moneyto coin int numQ, numD, numN, numP, remainder, // used to store left over values totalPenny, // needed for intermidiate result dollars; double moneyValue; // step 1-2 cout moneyValue; dollars = static_cast(moneyValue); totalPenny=(moneyValue-dollars)*100+.005; numQ = totalPenny / QUARTER; remainder = totalPenny % QUARTER; numD = remainder / DIME; remainder %= DIME; numN = remainder / NICKEL; numP = remainder % NICKEL; } // step 4, convert coin to money // code according to your spec; place the code inside the block else if(type == 'c') {coutdollars; coutnumQ; coutnumD; coutnumN; coutnumP; moneyValue=(dollars*100+numQ*25+numD*10+numN*5+numP)/100.; // put your code in this block } // step 5, display result goes below this line coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.