Skip to content

Instantly share code, notes, and snippets.

@rohan-cce
Last active December 26, 2024 08:08
Show Gist options
  • Save rohan-cce/9dbaae9d27fb142458bf4dd2db76ebcf to your computer and use it in GitHub Desktop.
Save rohan-cce/9dbaae9d27fb142458bf4dd2db76ebcf to your computer and use it in GitHub Desktop.
// inventory management system -> console based application
#include<stdio.h>
// new product
// int -> id
// string/ char arr -> name
// int-> quantity
// float -> price
// structure
#define MAX_ITEMS 100
typedef struct{
int id;
char name[50];
int quantity;
float price;
}Item;
Item inventory[MAX_ITEMS];
int itemCount = 0;
// adding items to the warehouse
void addItem(){
Item newItem;
printf("add items block\n");
printf("Enter id\n");
scanf("%d",&newItem.id);
getchar();
printf("Enter name \n");
fgets(newItem.name, sizeof(newItem.name), stdin);
printf("enter quantity \n");
scanf("%d",&newItem.quantity);
printf("enter price \n");
scanf("%f", &newItem.price);
inventory[itemCount] = newItem;
itemCount++;
printf("operation successfull !");
// arr[index] = value
// arr[0] = 1st product
// arr[1] = 2nd product
// arr[2] = 3rd product
}
void displayItems(){
for(int i=0; i<itemCount; i++){
printf("id is %d\n ",inventory[i].id);
printf("name is %s\n ",inventory[i].name);
printf("quantity is %d\n ",inventory[i].quantity);
printf("price is %f\n ",inventory[i].price);
}
}
int main(){
int choice;
do{
printf("\n\n\n Welcome to inventory management system\n");
printf("1. add an item\n");
printf("2. display all the items\n");
printf("3. search an item\n");
printf("4. delete an item\n");
printf("5. update an item\n");
printf("6. calculate the inventory value\n");
printf("7. exit the application");
printf("just input!\n");
scanf("%d",&choice);
switch(choice){
case 1:
addItem();
break;
case 2:
displayItems();
break;
case 3:
printf("3 input \n");
break;
case 4:
printf("4 input \n");
break;
case 5:
printf("5 input \n");
break;
case 6:
printf("6 input \n");
break;
case 7:
printf(" exiting :) \n");
break;
default:
printf("sorry we dont support thhis option");
}
}while(choice !=7);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment