### I need help with Modules operators!

My assignment is:

Enter amount of cents: 119 (assuming this is what the user types in)
Pennies: 4
Nickels: 1
Dimes: 1
Quarters: 4

And this is to assume each have their own obvious values, (example quarters = 25 cents, nickels 5 cents, dimes 10 cents etc.)

However, I am unsure of what exactly I'm supposed to do. My coding as of now is awfully sloppy and I'm told I require the modules operator. I know modules is the remainder of the two numbers after dividing, but I am confused on how it works in my current code.

Could someone give me useful tips or hints on my code?
 ``123456789101112131415161718192021222324252627282930313233343536`` `````` #include using namespace std; int main() { int amountCents; int pennies; int nickels; int dimes; int quarters; int amountLeft; cout << "Enter amount of cents:"; cin >> amountCents; amountLeft = amountCents % quarters; quarters = amountCents / 25; dimes = amountLeft / 10; nickels = (amountLeft % 10) / 5; pennies = nickels / 1; cout << "Quarters:" << quarters << endl; cout << "Dimes:" << dimes << endl; cout << "Nickels:" << nickels << endl; cout << "Pennies:" << pennies << endl; system("pause"); }``````
I am hoping my mode of thinking is right. When you use the modulus operator, it leaves the remainder. What you are wanting to do is to divide the total amount given by 25 to get the amount of quarters. If you modulus that same amount, it will give you the total to do the dimes on.

 ``1234567`` ``````cin >> amountCents; quarters = amountCents / 25 amountLeft = amountCents % 25 dimes = amountLeft / 10 amountLeft = amountLeft % 10``````

Work your way down to the Pennies. You wouldn't have to divide it since what is left from nickels would be all pennies.

I hope I have done the thinking right. You are the first post I attempted to answer. I believe I can learn better, the more I teach someone.
Topic archived. No new replies allowed.