MHB How to Efficiently Distribute Change Using Five and One Dollar Bills

  • Thread starter Thread starter moodtl32
  • Start date Start date
  • Tags Tags
    Change
Click For Summary
A cashier should distribute change by maximizing the number of five dollar bills before using one dollar bills. For an input amount, the number of five dollar bills can be calculated using integer division by 5. The number of one dollar bills can be determined using the modulus operator to find the remainder when the amount is divided by 5. The correct statement to assign the number of one dollar bills to the variable numOnes is "numOnes = amountToChange % 5." This method ensures efficient distribution of change.
moodtl32
Messages
2
Reaction score
0
A cashier distributes change using the maximum number of five dollar bills, followed by one dollar bills. For example, 19 yields 3 fives and 4 ones. Write a single statement that assigns the number of 1 dollar bills to variable numOnes, given amountToChange. Hint: Use the % operator.

#include <iostream>
using namespace std;

int main() {
int amountToChange;
int numFives;
int numOnes;

cin >> amountToChange;
numFives = amountToChange / 5;

/ Your Input Goes Here/

cout << "numFives: " << numFives << endl;
cout << "numOnes: " << numOnes << endl;

return 0;
}

my input was amountToChange = numOnes % 5;

Which is incorrect.
 
Physics news on Phys.org
moodtl32 said:
A cashier distributes change using the maximum number of five dollar bills, followed by one dollar bills. For example, 19 yields 3 fives and 4 ones. Write a single statement that assigns the number of 1 dollar bills to variable numOnes, given amountToChange. Hint: Use the % operator.

#include <iostream>
using namespace std;

int main() {
int amountToChange;
int numFives;
int numOnes;

cin >> amountToChange;
numFives = amountToChange / 5;

/ Your Input Goes Here/

cout << "numFives: " << numFives << endl;
cout << "numOnes: " << numOnes << endl;

return 0;
}

my input was amountToChange = numOnes % 5;

Which is incorrect.
FOUND THE ANSWER

numOnes = amountToChange % 5;
 
First trick I learned this one a long time ago and have used it to entertain and amuse young kids. Ask your friend to write down a three-digit number without showing it to you. Then ask him or her to rearrange the digits to form a new three-digit number. After that, write whichever is the larger number above the other number, and then subtract the smaller from the larger, making sure that you don't see any of the numbers. Then ask the young "victim" to tell you any two of the digits of the...

Similar threads

  • · Replies 3 ·
Replies
3
Views
15K
  • · Replies 3 ·
Replies
3
Views
1K
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K