A vector of small records can be summarized with a helper function and a range loop.

records A struct makes each inventory row clear: one count and one price.
summary The helper loops over records and returns a single value for the workflow.

Inventory Summary

extraCount
inventory_summary.cpp
Replay: real traced execution (multi-file project)
#include <iostream>
#include <vector>

struct Item {
    int count;
    int price;
};

int totalValue(const std::vector<Item>& items) {
    int total = 0;
    for (const Item& item : items) {
        total += item.count * item.price;
    }
    return total;
}

int main() {
    int extraCount = 2;

    std::vector<Item> items{{3, 10}, {extraCount, 8}};
    int value = totalValue(items);
    bool stocked = value >= 40;

    std::cout << "extraCount=" << extraCount << std::endl;
    std::cout << "value=" << value << std::endl;
    std::cout << "stocked=" << stocked << std::endl;
    return 0;
}
#include <iostream>
#include <vector>

struct Item {
    int count;
    int price;
};

int totalValue(const std::vector<Item>& items) {
    int total = 0;
    for (const Item& item : items) {
        total += item.count * item.price;
    }
    return total;
}

int main() {
    int extraCount = 0;

    std::vector<Item> items{{3, 10}, {extraCount, 8}};
    int value = totalValue(items);
    bool stocked = value >= 40;

    std::cout << "extraCount=" << extraCount << std::endl;
    std::cout << "value=" << value << std::endl;
    std::cout << "stocked=" << stocked << std::endl;
    return 0;
}
#include <iostream>
#include <vector>

struct Item {
    int count;
    int price;
};

int totalValue(const std::vector<Item>& items) {
    int total = 0;
    for (const Item& item : items) {
        total += item.count * item.price;
    }
    return total;
}

int main() {
    int extraCount = 5;

    std::vector<Item> items{{3, 10}, {extraCount, 8}};
    int value = totalValue(items);
    bool stocked = value >= 40;

    std::cout << "extraCount=" << extraCount << std::endl;
    std::cout << "value=" << value << std::endl;
    std::cout << "stocked=" << stocked << std::endl;
    return 0;
}
  1. extraCount ← 2, items ← (empty)

    17int main() {18    int extraCount→ 2 = 2; //@extraCount=0, 51920    std::vector<Item> items→ (empty){{3, 10}, {extraCount, 8}};21    int value = totalValue(items(empty));22    bool stocked = value >= 40;
  2. total ← 0

    9int totalValue(const std::vector<Item>& items(empty)) {10    int total→ 0 = 0;11    for (const Item& item : items) {
  3. total ← 30

    pass 1 of 2
    10int total = 0;11for (const Item& item(empty) : items(empty)) {12    total→ 30 += item.count3 * item.price10;13}
  4. total ← 46

    pass 2 of 2
    10int total = 0;11for (const Item& item(empty) : items(empty)) {12    total→ 46 += item.count2 * item.price8;13}
  5. return total;

    13    }14    return total46;15}
  6. value ← 46, stocked ← 1

    20    std::vector<Item> items{{3, 10}, {extraCount, 8}};21    int value→ 46 = totalValue(items(empty));22    bool stocked→ 1 = value46 >= 40;2324    std::cout << "extraCount=" << extraCount2 << std::endl;25    std::cout << "value=" << value46 << std::endl;26    std::cout << "stocked=" << stocked1 << std::endl;27    return 0;28}
    outputextraCount=2
    value=46
    stocked=1
  1. extraCount ← 0, items ← (empty)

    17int main() {18    int extraCount→ 0 = 0;1920    std::vector<Item> items→ (empty){{3, 10}, {extraCount, 8}};21    int value = totalValue(items(empty));22    bool stocked = value >= 40;
  2. total ← 0

    9int totalValue(const std::vector<Item>& items(empty)) {10    int total→ 0 = 0;11    for (const Item& item : items) {
  3. total ← 30

    pass 1 of 2
    10int total = 0;11for (const Item& item(empty) : items(empty)) {12    total→ 30 += item.count3 * item.price10;13}
  4. for (const Item& item : items)

    pass 2 of 2
    10int total = 0;11for (const Item& item(empty) : items(empty)) {12    total30 += item.count0 * item.price8;13}
  5. return total;

    13    }14    return total30;15}
  6. value ← 30, stocked ← 0

    20    std::vector<Item> items{{3, 10}, {extraCount, 8}};21    int value→ 30 = totalValue(items(empty));22    bool stocked→ 0 = value30 >= 40;2324    std::cout << "extraCount=" << extraCount0 << std::endl;25    std::cout << "value=" << value30 << std::endl;26    std::cout << "stocked=" << stocked0 << std::endl;27    return 0;28}
    outputextraCount=0
    value=30
    stocked=0
  1. extraCount ← 5, items ← (empty)

    17int main() {18    int extraCount→ 5 = 5;1920    std::vector<Item> items→ (empty){{3, 10}, {extraCount, 8}};21    int value = totalValue(items(empty));22    bool stocked = value >= 40;
  2. total ← 0

    9int totalValue(const std::vector<Item>& items(empty)) {10    int total→ 0 = 0;11    for (const Item& item : items) {
  3. total ← 30

    pass 1 of 2
    10int total = 0;11for (const Item& item(empty) : items(empty)) {12    total→ 30 += item.count3 * item.price10;13}
  4. total ← 70

    pass 2 of 2
    10int total = 0;11for (const Item& item(empty) : items(empty)) {12    total→ 70 += item.count5 * item.price8;13}
  5. return total;

    13    }14    return total70;15}
  6. value ← 70, stocked ← 1

    20    std::vector<Item> items{{3, 10}, {extraCount, 8}};21    int value→ 70 = totalValue(items(empty));22    bool stocked→ 1 = value70 >= 40;2324    std::cout << "extraCount=" << extraCount5 << std::endl;25    std::cout << "value=" << value70 << std::endl;26    std::cout << "stocked=" << stocked1 << std::endl;27    return 0;28}
    outputextraCount=5
    value=70
    stocked=1