. Write a program name Eggs that declares four variables to hold the number of eggs produced in a month by each of four chickens, and assign a value to each variable. Sum the eggs, then display the total in dozens and eggs. For example, a total of 127 eggs is 10 dozen and 7 eggs.

Respuesta :

Answer:

// code in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

   // variables

   int e1,e2,e3,e4;

   int tot,doz,rem_egg;

   cout<<"Enter the eggs given by first chicken:";

   // read the eggs given by first chicken

   cin>>e1;

   cout<<"Enter the eggs given by second chicken:";

   // read the eggs given by second chicken

   cin>>e2;

   cout<<"Enter the eggs given by third chicken:";

   // read the eggs given by third chicken

   cin>>e3;

   cout<<"Enter the eggs given by fourth chicken:";

   // read the eggs given by fourth chicken

   cin>>e4;

   // find total eggs

   tot=e1+e2+e3+e4;

   // find the dozens

   doz=tot/12;

   // remaining eggs

   rem_egg=tot%12;

   // print total eggs, dozen and remaining eggs

   cout<<"A total of "<<tot<<" eggs is "<<doz<<" dozen and "<<rem_egg<<" eggs.";

return 0;

}

Explanation:

Read the eggs given by four chickens and assign them to variables e1,e2,e3,e4 respectively.Then calculate the total eggs of all four chickens.After this find the dozen by dividing the total eggs with 12.To find the remaining eggs after the dozen and assign it to variable "rem_egg".Print the total eggs, dozen and remaining eggs.

Output:

Enter the eggs given by first chicken:40

Enter the eggs given by second chicken:23                                                                                  

Enter the eggs given by third chicken:55

Enter the eggs given by fourth chicken:60

A total of 178 eggs is 14 dozen and 10 eggs.