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

  • Thread starter Thread starter moodtl32
  • Start date Start date
  • Tags Tags
    Change
AI Thread 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;
 
Back
Top