Determining the maximum value that can be obtained from a loot A thief finds much more loot than his bag can fit. We have to find the most valuable combination of items assuming that any fraction of a loot item can be put into his bag.

For example has a bag which can fit at most 50 Kg of items. He has 3 items to choose from: the first item has a total value of $60 for 20 Kg, the second item has a total value of $100 for 50 Kg and the last item has a total value of $120 for 30 Kg.

So, if the thief takes the most of the item that costs more per unit Kg, he/she can make a better profit out of his/her thievery. In that case, he/she would take 30 Kgs of the third item, and 20 Kgs of the first item, resulting in a total of 50 Kgs (full capacity) with the total value of $180.

// THIS IS AN EXAMPLE OF THE FRACTIONAL KNAPSACK PROBLEM

#include&lt;cstdio&gt;
#include&lt;iostream&gt;
#include&lt;vector&gt;
using namespace std;
double get_max_index(vector&lt;int&gt;, vector&lt;int&gt;);
double get_max_value(vector&lt;int&gt;, vector&lt;int&gt;, int);

int main() {

    int num_items, bag_capacity;
    cout &lt;&lt; "Enter the number of items: " &lt;&lt; endl;
    cin &gt;&gt; num_items;
    cout &lt;&lt; "Enter the total capacity that the bag can support: " &lt;&lt; endl;
    cin &gt;&gt; bag_capacity;

    vector&lt;int&gt; values;
    vector&lt;int&gt; weights;

    for (int i = 0; i &lt; num_items; i++)
    {
        int buff_val = 0, buff_wgt = 0;
        cout &lt;&lt; "Enter the value and weight of Item " &lt;&lt; i + 1 &lt;&lt; ": " &lt;&lt; endl;
        cin &gt;&gt; buff_val &gt;&gt; buff_wgt;
        values.push_back(buff_val);
        weights.push_back(buff_wgt);
    }

    cout.precision(10);
    cout &lt;&lt; "The maximum loot value that can be acquired is " &lt;&lt; fixed &lt;&lt; get_max_value(values, weights, bag_capacity) &lt;&lt; "." &lt;&lt; endl;          // Always display 'precision' number of digits

    return 0;
}

double get_max_index(vector&lt;int&gt; vals, vector&lt;int&gt; wgts){
    int max_index = 0;
    double max_val_per_wgt = 0;
    for (int i = 0; i &lt; wgts.size(); i++)
    {
        if (wgts[i] != 0 &amp;&amp; (double) vals[i] / wgts[i] &gt; max_val_per_wgt)
        {
            max_val_per_wgt = (double) vals[i] / wgts[i];
            max_index = i;
        }
    }
    return max_index;
}

double get_max_value(vector&lt;int&gt; vals, vector&lt;int&gt; wgts, int capacity){

    double max_val = 0.0;
    for(int i = 0; i &lt; wgts.size(); i++) {
        if (capacity == 0)
        {
            return max_val;             // There's no space left in the bag to carry
        }
        int max_value_index = get_max_index(vals, wgts);     // See which item has the best value per weight index
        double taken = capacity &gt; wgts[max_value_index] ? wgts[max_value_index] : capacity;     // get the minimum of the item's weight and capacity left in the bag
        max_val += taken * (double) vals[max_value_index] / wgts[max_value_index];      // calculate value for the item's weight taken
        capacity -= taken;          // reduce capacity of the bag by the amount of weight of item taken
        wgts[max_value_index] -= taken;         // reduce the item's weight by the amount taken
    }
    return max_val;
}


Please review this code in terms of complexity or in other areas that might result in this code failing. Also, looking forward to criticism and if you decide to post criticism, kindly include relevant details that a not-so-experienced programmer might find helpful in solving the problem.
The algorithm
Your algorithm needs O(n) space (for storing all items), and O(n * k) time (for selecting the best ones) (n = items to choose from, k = items chosen, bounded by n).
By choosing as you go, you can get that down to O(k') space and O(n * k') time (k' = maximum items chosen at any time, at least k, bounded by n).
Take a look at std::push_heap, std::tuple and lambdas for implementing the new algorithm.
Avoid casting
Casting is error-prone, as it circumvents the protections of the type-system. Thus, use the most restricted cast you can, and don't cast at all if reasonably possible. In your case, why not multiply with 1.0 instead?
Floating-point is hard
You are calculating the specific value (value per weight) of your items for comparison purposes. Luckily, a double has enough precision that you are extremely unlikely to suffer from rounding-errors when dividing two 32 bit numbers. Still, instead of comparing 1.0 * a_value / a_weight &lt; 1.0 * b_value / b_weight you could compare 1LL * a_value * b_weight &lt; 1LL * b_value * a_weight, avoiding division and floating-point.
All those useless copies
While copying small trivial types is generally the right approach, a std::vector is neither small nor trivial; Copying it is rather expensive. If you only need to read it, use a constant reference or preferably a C++2a std::span for increased flexibility.
Gracefully handle all kinds of invalid input
No need to assume malice, you are assured your load of garbage anyway.
Just the code

I don't see where you use anything from &lt;cstdio&gt;, so don't include it.

Never import a namespace wholesale which isn't designed for it. Especially std is huge and ever-changing, which can silently change the meaning of your code even between minor revisions of your toolchain, let alone using a different one.
It cannot be guaranteed to break noisily.

return 0; is implicit for main(). Make of that what you will.