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