Answer to Question #312126 in C++ for Ali

Question #312126

An egg distribution company uses different sizes of packings for eggs, that is, 30 eggs packing, 24 eggs packing, 18 eggs packing, 12 eggs packing and 6 eggs packing. Write a program which prompts user to enter total number of eggs (input validation is always must) to be packed and then calculate how many packings of each size will be possible. Also tell if there will be any eggs left to be packed.

Not to use Loops , functions,arrays and pointers.


1
Expert's answer
2022-03-15T13:00:03-0400
#include <iostream>

using namespace std;

int main()
{
	int eggs;
	cout << "Please, enter the total number of eggs: ";
	cin >> eggs;
	int pack30=0, pack24=0, pack18=0, pack12=0, pack6 = 0;
	if (30 <= eggs)
	{
		pack30 = eggs / 30;
		eggs = eggs - pack30 * 30;
	}
	if (24 <= eggs)
	{
		pack24 = eggs / 24;
		eggs = eggs - pack24 * 24;
	}
	if (18 <= eggs)
	{
		pack18 = eggs / 18;
		eggs = eggs - pack18 * 18;
	}	
	if (12 <= eggs)
	{
		pack12 = eggs / 12;
		eggs = eggs - pack12 * 12;
	}
	if (6 <= eggs)
	{
		pack6 = eggs / 6;
		eggs = eggs - pack6 * 6;
	}
	cout << "We need to use:\n"
		<< pack30 << " of 30 eggs packing\n"
		<< pack24 << " of 24 eggs packing\n"
		<< pack18 << " of 18 eggs packing\n"
		<< pack12 << " of 12 eggs packing\n"
		<< pack6 << " of 6 eggs packing\n";
	if(eggs>0)
		cout << eggs << " eggs left to be packed";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment