A C++ program is required that calculates the amount, in dollars. contained in a
ID: 3636035 • Letter: A
Question
A C++ program is required that calculates the amount, in dollars. contained in a piggy bank. The bank contains half dollars, quarters. dimes, nickels. and pennies. For this programming problem, how many outputs arc required? 1 low many inputs does this problem have? Write an algorithm for converting the input items into output items. Test the algorithm written for Exercise 1c using the following sample data: half dollars 0. quarters 17. dimes 24. nickels 16. and pennies 12.Explanation / Answer
a) there is only one output, that is the dollars. b) there are 5 inputs, namely, half dollars, quarters, dimes, nickels and pennies. c) // money.cpp #include #include using namespace std; // Algorithm total_cents // Input: a string of user entered currency denominations (quarters, dimes, etc) // Output: The amount of money converted to pennies // dollars, 50 cents pieces, quarters, dimes, pennies >> total_cents // total_cents=pennies + (nickels*5) + (dimes*10) + (quarters*25) + (half_dollar*50) + (dollars*100) // total_dollars=total_cents/100 void getNumber(float &myvar); // C++ programs start by executing the function main, and ours doesn't take any command line arguments int main(void) { float dollars = 0, half_dollar = 0, quarters = 0, dimes = 0, nickels = 0, pennies = 0, total_cents = 0, total_dollars = 0; string s_add = "s", s_dollars = "dollar", s_half_dollar = "half dollar", s_quarters = "quarter", s_dimes ="dime", s_nickels = "nickle", s_penny = "penny", s_cent = "cent"; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.