Answer to Question #218681 in C++ for Max

Question #218681
Management of Charles Saah & Associate a poultry farm has realized that the staff are
stealing the eggs that are harvested, counted and kept in stock. This is because they
cannot check how many eggs have been sold, and how many left. After several
consultations they decided to automate the stock taking process. The chief executive
officer Charles Saah, contacted Charles Saah of AiT Systems (CSAiTS) to help develop
a system for the automation. It was decided that the software for the automation should
perform the following when installed. Assuming that a crate of egg cost GHS20 and only
full crates of eggs are to be sold.
a. Take the name of the person harvesting the eggs, the total crates of eggs
harvested and stocked.
b. Allow eggs to be sold in creates but, cannot sell more crates of eggs than in stock.
This process should be performed five time each time compare the stock level as
you cannot sell more than what is in stock.
C. Explain the logic behind your code.
1
Expert's answer
2021-07-19T16:59:44-0400
#include<iostream>
using namespace std;
int main(){
	int totalCratesInStock;
	cout<<"Enter the total number of crates in the stock\n";
	cin>>totalCratesInStock;
	string name;
	int total_crates;
	int numberCratesStocked;
	cout<<"The name of the person doing harvesting\n";
	cin>>name;
	cout<<"Enter the number of crates of eggs stocked\n";
	cin>>total_crates;
	cout<<"Enter the number of crates stocked\n";
	cin>>numberCratesStocked;
	totalCratesInStock = totalCratesInStock + numberCratesStocked;
	int crates_sell;
	
	int i = 0;
	while(i<5){
	cout<<"Enter the number of crates to sell\n";
	cin>>crates_sell;
		if(crates_sell>totalCratesInStock){
			cout<<"The number of crates to be sold should not be greater than the crates in the stock\n";
		}
		else{
			totalCratesInStock = totalCratesInStock - crates_sell;
			break;
		}
	}
	cout<<"The total crates sold are:\t"<<crates_sell<<endl<<"The total crates left are:\t"<<totalCratesInStock;
}

The logic behind this code is very simple. It first ask the user to enter the name of the worker harvesting the eggs. Then takes the number of crates harvested and then add to the the number of crates in the stock. When a user want to sell it checks the number of crates to be sold and the crates number in the stock. If the number of crates to be sold exceeds the one in the stock, the user is asked again to enter the number of crates.


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