Answer to Question #328106 in C++ for Christine

Question #328106

Read this story and calculate/print the x total eggs collected between Monday and Wednesday:



Mang Jose’s chickens always lay eggsPerChicken eggs precisely at noon, which he collects that day.



• On Monday, Mang Jose has chickenCount chickens.



• On Tuesday morning, Mang Jose gains 1 chicken.



• On Wednesday morning, a wild beast eats half the chickens!



For Example:



• If Mang Jose starts with eggsPerChicken = 5 and chickenCount = 3, he must then collect a total of 45



eggs



• If Mang Jose starts with eggsPerChicken = 4 and chickenCount = 8, he must then collect a total of 84



eggs



Develop a C++ program that calculates how many eggs will Mang Jose collects based on user input.

1
Expert's answer
2022-04-13T10:33:08-0400
#include <iostream>


int main() {
  int chickenCount;
  int eggsPerChicken;
  std::cout << "Enter amount of chickens: ";
  std::cin >> chickenCount;
  std::cout << "Enter amount of eggs per chicken: ";
  std::cin >> eggsPerChicken;
  int total = 0;


  // Monday
  total += chickenCount * eggsPerChicken;


  // Tuesday
  ++chickenCount; // new chicken
  total += chickenCount * eggsPerChicken;


  // Wednesday
  chickenCount /= 2; // a wild beast eats half the chickens! 
  total += chickenCount * eggsPerChicken;


  std::cout << "Total amount of eggs: " << total << '\n';
  return 0;

}




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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS