Answer to Question #231295 in C++ for Zodiak

Question #231295

a program where customers can buy a certain packets of Chips and Apples when they are still available. for each transaction the user must enter the number of packets of one type to buy. if that number is still available, subtract it from the total packets still available. Use a sentinel to terminate the loop.


1
Expert's answer
2021-08-30T17:59:59-0400
#include<iostream>
using namespace std;
int main(){
int availablePacketsOfChips = 100; //Initializing the total number of avaialable packets of chips
int availablePacketOfApples = 100;	//Initializing the total number of avaialable packets of apples
int numberOfChips, numberOfApples;
do{
	
	cout<<"Enter the number of chips to buy\n";
	cin>>numberOfChips;
	cout<<"Enter the number of apples to buy\n";
	cin>>numberOfApples;
	availablePacketOfApples = availablePacketOfApples - numberOfApples;


	availablePacketsOfChips = availablePacketsOfChips - numberOfChips;
	
	if(availablePacketsOfChips > 0 && availablePacketOfApples >0 ){
		cout<<"The remaining packets of chips: "<<availablePacketsOfChips<<endl;
	   cout<<"The remaining packets of apples: "<<availablePacketOfApples<<endl;
	}
}
while(0<availablePacketsOfChips && 0<availablePacketOfApples);
cout<<"No packets\n";
}

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