In: Computer Science
Answer this question on a new project. Use comments to explain
how your program works, final cpp to be uploaded just like you do
the assignments.
A box of biscuit is able to hold 10 biscuits,
A container is capable of holding 25 boxes (equivalent to 250
biscuits), and
A truck is capable of moving 5 containers (equivalent to 1250
biscuits).
Write a C++ program that takes in an order of biscuits as input,
determines and outputs the following; how many fully loaded trucks
it will take to move the order, along with the spare containers,
boxes and leftover biscuits you will have left. (DO NOT USE
ANYTHING NOT YET COVERED IN CLASS. ALSO, FOR ACCURATE RESULTS, USE
INTEGER VARIABLES FOR ENTIRE PROGRAM)
Example Results,
For an input of 14926 biscuits,
it should output
It takes 11 truck(s), 4 container(s), and 17 box(es) to store the order
There are 6 leftover biscuits
For input 8163 biscuits,
it should output
It takes 6 truck(s), 2 container(s), and 16 box(es) to store the order
There are 3 leftover biscuits
5 points extra credit if your output looks EXACTLY as above
Explanation of Calculation
To determine the number of trucks, you are dividing the number of biscuits by how many a truck can store.
Take a 2950 biscuit order as an example,
2950 / 1250 gives you 2. So 2950 biscuits will need 2 trucks, which can store 2500 biscuits
There are 450 biscuits leftover. This cannot fill a truck so you find how many containers
similar process as above
450 / 250 gives you 1. So 450 biscuits will need 1 container which can store 250 of the biscuits
There are 200 biscuits left. (and so on and so forth)
#include <iostream>
using namespace std;
int main()
{
int Biscuits;
int trucks,containers,Biscuits_left,boxes=0; //intially all variables are taken as zero.
cout << "Enter No of Biscuits:";
cin >> Biscuits;
trucks = Biscuits/1250; // calculates the trucks needed.
Biscuits_left = Biscuits % 1250; // % used to calculate biscuits left after calculating the trucks needed.
if(Biscuits_left>0) // it checks for the any buscits left
{
containers = Biscuits_left/250;
Biscuits_left = Biscuits_left%250;
if(Biscuits_left>0) // executes when any biscuits left after calculating the containers.
{
boxes = Biscuits_left/10;
Biscuits_left = Biscuits_left%10; //caluates the final result for biscuits left
cout << " it takes " << trucks << " truck(s), " << containers <<" container(s), and " << boxes <<" Box(es) to store the order";
cout <<"\n There are " << Biscuits_left <<" biscuits left";
}
}
else // executes when there are no biscuits left after calculating the trucks
{
cout << " it takes " << trucks << " truck(s), " << containers <<" container(s), and " << boxes <<" Box(es) to store the order";
cout <<"\n There are " << Biscuits_left <<" biscuits left";
}
return 0;
}
output:
Enter No of Biscuits:14946
it takes 11 truck(s), 4 container(s), and 19 Box(es) to store the order
There are 6 biscuits left
Enter No of Biscuits:1250
it takes 1 truck(s), 0 container(s), and 0 Box(es) to store the order
There are 0 biscuits left
Enter No of Biscuits:151678
it takes 121 truck(s), 1 container(s), and 17 Box(es) to store the order
There are 8 biscuits left