Doubt in the code

please check my code I am getting runtime errror

@Adhyayan,
Instead of using if statements, use else-if in the knapsack.

				if (cap >= w[i - 1]) {

In the above line use else if, because in case i==0, it will give out of bounds exception


the output is coming wrong ,please check the logic…

@Adhyayan,
https://ide.codingblocks.com/s/260293 corrected code.
Small errors in 2 lines. I have highlighted the lines for reference