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;
 
There is a nice little variation of the problem. The host says, after you have chosen the door, that you can change your guess, but to sweeten the deal, he says you can choose the two other doors, if you wish. This proposition is a no brainer, however before you are quick enough to accept it, the host opens one of the two doors and it is empty. In this version you really want to change your pick, but at the same time ask yourself is the host impartial and does that change anything. The host...

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