At least part of the problem is that you are not understanding how operators work in C++.
for(i=1;i<=n,completed==0;i++){
The expression i<=n,completed==0 has the effect of evaluating i <= n, discarding the result, then evaluating completed == 0, and giving the result of that.
So the end condition of the loop is essentially completed == 0. The relationship between i and n does not affect execution of the loop.
There are certainly other problems too, but I haven’t looked further.
5
solved Function receiving different value than passed