You have a large collection of pennies and wish to change them into dollar bills at the bank, with quarters, dimes, nickels, and pennies being used for any remainder. Prompt for the number of pennies and produce output as shown below.
Output:
How many pennies do you have (must be greater than 100)? [Assume user inputs 641]
641 pennies can be changed at the bank as follows:
Dollars: 6
Quarters: 1
Dimes: 1
Nickels: 1
Pennies: 1
#include <iostream>
using namespace std;
int main()
{
int a;
cout<<"How many pennies do you have (must be greater than 100)?\n";
cin>>a;
cout<<a<<" pennies can be changed at the bank as follows:\n";
int D = a / 100;
a -= 100 * D;
cout<<"Dollars: "<<D<<"\n";
int q = a / 25;
a -= 25 * q;
cout<<"Quarters: "<<q<<"\n";
int d = a / 10;
a -= 10 * d;
cout<<"Dimes: "<<d<<"\n";
int n = a / 5;
a -= 5 * n;
cout<<"Nickels: "<<n<<"\n";
cout<<"Pennies: "<<a<<"\n";
return 0;
}
Comments
Leave a comment