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.

Respuesta :

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

The statement will be implemented using the modulo operator.

The function of the modulo operator (%) is to return the remainder of an integer division.

Take for instance:

[tex]\mathbf{5\% 3=2}[/tex]

This is so because, when 5 is divided by 3; the remainder is 2

So, the required programming statement is:

numberOfOnes = amtToChange % 5;

The above statement is the same for several programming languages such as Python, Java, C++, C#, C, etc.

Read more about modulo operator at:

https://brainly.com/question/24208941

Q&A Education