Ask Question
14 December, 22:15

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.

+5
Answers (2)
  1. 14 December, 22:17
    0
    numOnes = amountToChange % 5;

    Explanation:

    The modulus operator % returns the remainder after division.

    To get the number of dollar bills, you need to know how much remains if you divide by 5. And that is exactly what the above statement does.
  2. 14 December, 22:41
    0
    A C program that assigns the number of 1 dollar bills:

    int main () {

    int amtToChange = 0;

    int numberofFives = 0;

    int numberofOnes = 0;

    amtToChange = 19;

    numberofFives = amtToChange / 5;

    numberOfOnes = amtToChange % 5;

    cout << "numFives: " << numberofFives << endl;

    cout << "numOnes: " << numberofOnes << endl;

    return 0;

    }

    The single statement is numberOfOnes = amtToChange % 5
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “A cashier distributes change using the maximum number of five dollar bills, followed by one dollar bills. For example, 19 yields 3 fives ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers