In: Computer Science
Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies.
Ex: If the input is:
0
(or less than 0), the output is:
No change
Ex: If the input is:
45
the output is:
1 Quarter 2 Dimes
c++ please
#include <iostream> using namespace std; int main() { int userNum, value; cin >> userNum; if (userNum <= 0) cout << "No change" << endl; else { value = userNum / 100; userNum %= 100; if (value == 1) cout << value << " Dollar" << endl; else if (value > 1) cout << value << " Dollars" << endl; value = userNum / 25; if (value == 1) cout << value << " Quarter" << endl; else if (value > 1) cout << value << " Quarters" << endl; userNum = userNum % 25; value = userNum / 10; if (value == 1) cout << value << " Dime" << endl; else if (value > 1) cout << value << " Dimes" << endl; userNum = userNum % 10; value = userNum / 5; if (value == 1) cout << value << " Nickel" << endl; else if (value > 1) cout << value << " Nickels" << endl; userNum = userNum % 5; if (userNum == 1) cout << userNum << " Penny" << endl; else if (userNum > 1) cout << userNum << " Pennies" << endl; } return 0; }