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.
#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;
}
Comments
Leave a comment