A box of cookies can hold 24 cookies, and a container can hold 75 boxes of cookies. Write a program that prompts the user to enter: The total number of cookies The program then outputs: The number of boxes and the number of containers to ship the cookies. Note that each box must contain the specified number of cookies, and each container must contain the specified number of boxes. If the last box of cookies contains less than the number of specified cookies, you can discard it and output the number of leftover cookies. Similarly, if the last container contains less than the number of specified boxes, you can discard it and output the number of leftover boxes.

Respuesta :

ANSWER

The cpp program is given below.

#include <iostream>

using namespace std;

int main() {

   // variables declared and initialized with given values

   int box_capacity = 24;

   int boxes = 0;

   int container_capacity = 75;

   int containers =0;

   int cookies;

   

   // user input taken for number of cookies

   cout<< "Enter the number of cookies to be shipped: ";

   cin>>cookies;

   

   // boxes and containers computed based on given values

   while(cookies>box_capacity)

   {

       cookies = cookies - box_capacity;

       boxes = boxes +1;

       

       if(boxes == container_capacity)

           containers = containers +1;

           

   }

   

   // outputting the required boxes and containers

   cout<<boxes<< " number of boxes " << " and " <<containers<< " number of containers are required to ship the cookies." <<endl;

  return 0;   

}

OUTPUT1

Enter the number of cookies to be shipped: 23

0 number of boxes  and 0 number of containers are required to ship the cookies.

OUTPUT2

Enter the number of cookies to be shipped: 230

9 number of boxes  and 0 number of containers are required to ship the cookies.

OUTPUT3

Enter the number of cookies to be shipped: 2300

95 number of boxes  and 1 number of containers are required to ship the cookies.

EXPLANATION:

The program is described below.

1. Variables are created and initialized to hold all the given values for capacity.

2. Variables are created and initialized to 0 to hold number of boxes and containers.

3. User input is taken in the variable, cookies.

4. All the variables are declared as integers since no decimals are involved.

5. Inside while loop, the number of boxes and containers are computed.

6. The while loop executes since value of cookies does not falls below the capacity of the box, box_capacity.

7. The program terminates with the return statement.

8. Three different outputs are shown based on the different values of cookies.

9. The output shows the values of variables boxes and containers based on the user input for cookies variable.