This question should be done in CLanguage Suppose you own a
This question should be done in C-Language
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 transaction 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 negative integer value). For now you may assume that you always have sufficient 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.)
Copyright | Pearson | Problem Solving and Program Design in C | Edition 8 | icloud.com | Printed from www.chegg.com
Solution
#include <stdio.h>
int main (void) {
int inv1, inv2, inv3, inv4;
inv1 = inv2 = inv3 = inv4 = 0;
printf (\"Beer brand IDs \ \");
printf (\"1. Piels\ 2. Coors\ 3. Bud\ 4. Iron City\ \ \");
printf (\"Inventory at beginning of week\ \");
printf (\"1. Piels : \");
if (scanf (\"%d\", &inv1) != 1) {
fprintf (stderr, \"error: invalid input.\ \");
return 1;
}
printf (\"2. Coors : \");
if (scanf (\"%d\", &inv2) != 1) {
fprintf (stderr, \"error: invalid input.\ \");
return 1;
}
printf (\"3. Bud : \");
if (scanf (\"%d\", &inv3) != 1) {
fprintf (stderr, \"error: invalid input.\ \");
return 1;
}
printf (\"4. Iron City: \");
if (scanf (\"%d\", &inv4) != 1) {
fprintf (stderr, \"error: invalid input.\ \");
return 1;
}
while (1) {
int amount = 0, code = 0;
printf (\"ID (\'q\' to quit): \");
if (scanf (\"%d\", &code) != 1) break;
printf (\"amount requested or subtracted: \");
if (scanf (\"%d\", &amount) != 1) break;
if (code == 1)
inv1 -= amount;
else if (code == 2)
inv2 -= amount;
else if (code == 3)
inv3 -= amount;
else if (code == 4)
inv4 -= amount;
else
fprintf (stderr, \"warning: ID out of range.\ \");
}
printf (\"\ End of week for Piels : %d\ \", inv1);
printf (\"End of week for Coors : %d\ \", inv2);
printf (\"End of week for Bud : %d\ \", inv3);
printf (\"End of week for Iron City : %d\ \", inv4);
return (0);
}

