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