I WANT TO RUN THIS ON MATRIX and use C language for this pr
**** I WANT TO RUN THIS ON MATRIX and use C language for this problem
In thisworkshop, you are going to use a C structuretype to represent anItemof an inventory. Apersonis able to viewthe inventory, add an item to the inventory, and check prices for items in the inventory. Here is the C structure type that should be used in this workshop:
structItem{
intsku_;
floatprice_;
intquantity_;
};
sku_: Stock Keeping Unit number for an item.
price_: Price for an item.
quantity_: Quantity of an item.
Also, use constor #define directivesto define the following number:
MAX_ITEMS: the maximum number of items that exists in an inventory. Assume MAX_ITEMSis 10.
In your main function, implement the following steps:
1. Define the following variables in your main program:
structItem item[MAX_ITEMS]; //An array of Item representing the inventory
intsize=0; //Number of items in the inventory. The inventory is initially empty.
2. Display awelcome massage:
Welcome to the Shop
===================
3. Display the following menu, and prompt the user to select anoption from the menu.
Please select from the following options:
1) Display the inventory.
2) Add to the inventory.
0)Exit.
4.You must verify that the input integer is between zero and two inclusive.If the input number is not between zero and two, you must display a warning and prompt the user again. You can assume the user will only enter numbers.The program only exits when the user selects 0 (Exit) on the menu screen (looping required).
5. Depending on the user’s input, one of the following scenarios happens.
Add to the inventory:
Prompt the user to input the SKU number and the quantity of an item that one wants to add to the inventory.
Search through the inventory (the item array) to find if the item exists in the array.
If the item is found in the inventory, do the following:
Update the quantity of the item by adding the quantity read to the quantity of the item in array.
Display a message that the item quantity is successfully updated.
If the item is not found in the inventory, do the following:
If the inventory is full (size== MAX_ITEMS), display the inventory is full.
If the inventory is not full, the function prompts the user to input item price. Then, update the inventory. Hint: Use the inventory array, and size as its index, and assign sku, price and quantity. Increment size.
Display the inventory:
Display the inventory in an informative format. See sample output.
Exit:
Display a goodbye message:
Goodbye!
Your program is complete if your output matches the following output. Red numbers show the user’s input.
Welcome to the Shop Please select from the following options: 1) Display the inventory 2) Add to shop 0) Exit Select8 Invalid input, try again: Please select from the following options: 1) Display the inventory 2) Add to shop 0) Exit. Select2 Please input a SKU number 2341 Quantity3 Price:1xi The item is successfully added to the inventory Please select from the following options: 1) Display the inventory 2) Add to shop. 0) Exit. Select Please input a SKU number 4567 Quantity: Price 98x2 The item is successfully added to the inventory Please select from the following options: 1) Display the inventory 2) Add to shop. 0) Exit. Select;Solution
#include <stdio.h>
#include <stdlib.h>
// define maximum number of items
const MAX_ITEMS = 10;
//struct to use as asked in problem
struct Item{
int sku_;
float price_;
int quantity_;
};
int main(){
struct Item item[MAX_ITEMS]; // array of item representing the inventory
int size = 0; //number of items in the inventory initially its empty
// temporary variable to store the user input
int tempSku, tempQuantity;
float tempPrice;
printf(\"\ \\t\\tWelcome to the Shop\ \\t\\t===================\ \ \");
while(1){
printf(\"\\t\\tPlease select from the following options:\ \"
\"\\t\\t1) Display the inventory.\ \"
\"\\t\\t2) Add to the inventory.\ \"
\"\\t\\t0)Exit.\ \\t\\tSelect: \");
int c; // variable where we store the options
scanf(\"%d\", &c);
switch(c){
case 1:
printf(\"\ \\t\\tInventory\ \\t\\t=========================================\ \");
printf(\"\\t\\tSku\\t\\tPrice\\t\\tQuantity\ \ \");
// print the inventory by iterating through item[]
int i;
for(i = 0; i < size; ++i){
printf(\"\\t\\t%d\\t\\t%f\\t\\t%d\ \ \",item[i].sku_, item[i].price_, item[i].quantity_);
}
printf(\"\\t\\t=========================================\ \ \");
break;
case 2:
printf(\"\ \\t\\tPlease input a SKU number: \");
scanf(\"%d\", &tempSku);
printf(\"\\t\\tQuantity: \");
scanf(\"%d\",&tempQuantity);
printf(\"\\t\\tPrice: \");
scanf(\"%f\", &tempPrice);
if(size >= MAX_ITEMS){
printf(\"\ \\t\\tItem can\'t be added, Inventory is full\ \ \");
break;
}
// assign these temporary variable and increase the size of inventory
item[size].sku_ = tempSku;
item[size].quantity_ = tempQuantity;
item[size].price_ = tempPrice;
size++;
printf(\"\ \\t\\tItem is successfully added to the inventory\ \ \");
break;
case 0:
return 0;
default:
printf(\"\ \\t\\tInvalid Input, try again\ \ \");
}
}
return 0;
}
I have commented it for better understanding in some places. You can change the way you want to see the inventory by removing or adding \\t or \ . If you have any doubt you can ask me.


