This is supposed to be in written in C Suppose you own a bee

This is supposed to be in written in C

Suppose you own a beer distributorship that sells Piels (ID number 1), Coors (ID number 2), Bud (ID number 3), and Iron City (ID number 4) by the case. Write a program to

a. Get the case inventory for each brand for the start of the week.

b. Process all weekly sales and purchase records for each brand.

c. Display out the final Inventory.

Each trasaction will consist of two data items. The first item will be the brand ID number (an integer). The second will be the amount purchased (a positive integer value) or the amount sold (a negetive integer value). For now you may assume that you always have sufficent foresight to prevent depletion of your inventory for any brand. (Hint: Your data entry should begin with four values representing the case inventory, followed by the transaction values.)

Solution

#include <stdio.h>

struct beerCase{
   int id;
   int currentAmountInTheStore;

} beers[5]; //for id=1 to id=4

char* beerCaseNames[5] = {\"Null\", \"Peils\",\"Coors\",\"Bud\",\"Iron City\"};
//id 0 doesnt represent any beer

int main(){
   //get initial case inventory
   int number;
   printf(\"Enter case inventory for the start of the week\ \");
   int beerNo = 1;
   for( ; beerNo <= 4; beerNo++ ){
       printf(\"For %s (ID number %d): \", beerCaseNames[beerNo], beerNo );
       scanf(\"%d\", &number );
       beers[ beerNo ].id = beerNo;
       beers[ beerNo ].currentAmountInTheStore = number;
   }

   //process sales and purchases  
   printf(\"Enter total number of weekly sales and purchase records, you need to process: \");
   int totalRecords;
   scanf(\"%d\",&totalRecords);
   int beerBrandId;
   int amount;
   while( totalRecords-- ){
       printf(\"Enter brand id: \");
       scanf(\"%d\", &beerBrandId);
       printf(\"Enter amount purchased/sold (-ve if sold): \");
       scanf(\"%d\", &amount);

       if( beerBrandId < 1 || beerBrandId > 4 ){
           printf(\"Invalid brand id : Incorrect transaction, re-enter\ \");
           totalRecords++;
           continue;
       }
       if( beers[beerBrandId].currentAmountInTheStore + amount < 0 ){
           printf(\"Transaction showing more sold, than is in store : Incorrect transaction, re-enter\ \");
           totalRecords++;
           continue;
       }
       //updating the amount
       beers[ beerBrandId ].currentAmountInTheStore += amount;
   }

   printf(\"Displaying final inventory\ \");
   beerNo = 1;
   printf(\"Beer Brand Id\\tCase Inventory\ \");
   for(; beerNo <= 4; beerNo++ ){
       printf(\"%d\\t\\t%d\ \", beerNo, beers[ beerNo ].currentAmountInTheStore );
   }

   return 0;
}

This is supposed to be in written in C Suppose you own a beer distributorship that sells Piels (ID number 1), Coors (ID number 2), Bud (ID number 3), and Iron C
This is supposed to be in written in C Suppose you own a beer distributorship that sells Piels (ID number 1), Coors (ID number 2), Bud (ID number 3), and Iron C

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site