HOME HTML EDITOR C JAVA PHP

C Structures Challenge: The "Inventory Manager"

Now that you know how to group data using struct, your task is to build a basic Inventory Management system. This will test your ability to define a structure, manipulate its members, and work with an Array of Structs.

The Goal: Track Warehouse Products

You need to create a program that can store information for multiple products in a warehouse and then calculate the total value of the inventory.

Challenge Requirements

To pass this challenge, your code must implement the following:

---

Stuck? Here is the Professional Template

Try to write the logic from scratch first. If you need a hint on the syntax for an array of structs, look at the structure below:

#include <stdio.h>
#include <string.h>

struct Product {
    char name[30];
    float price;
    int quantity;
};

int main() {
    // Array of 3 products
    struct Product inventory[3] = {
        {"Laptop", 800.00, 5},
        {"Mouse", 25.50, 20},
        {"Keyboard", 50.00, 10}
    };

    float grandTotal = 0;

    // Your loop logic goes here...

    return 0;
}

Bonus Challenges for Pro Coders

  1. The Arrow Operator: Use a pointer to access your struct members inside the loop using ptr->member syntax.
  2. User Search: Ask the user to enter a product name, then search the array and print the details of only that specific product.
  3. TypeDef: Refactor your code using typedef so you don't have to keep writing the struct keyword.
Technical Tip: When using scanf with strings inside a struct, remember that the name of the array (inventory[i].name) is already an address, so you don't need the & symbol!