To be more explicit than jonnin, it appears that printf() is working just fine. It is significantly more likely that your calculation is incorrect.
"objFunction" is a very odd name to give an integer type variable, kind of like having a pet dog named "bird". Even a simple name like "objFunctionResult" might be better?
Or, better yet, why not make it a function returning a value:
1 2 3 4 5 6
int obj_function()
{
int result = 0;
...
return result;
}
I recognize that you are new at this, but even so, try to get rid of all those system("pause"); in your program. If necessary, have just one at the end of main().
I can't imagine any kind of solution requiring a n4 loop like you have set up there. What is the problem you are trying to solve here?
I don't know what your loops are doing, but I'd debug it by separating out everything into 4 variables, then putting a breakpoint on the += line:
1 2 3 4 5
int var1 = flow[i][k];
int var2 = dist[j][q];
int var3 = x[i][j];
int var4 = x[k][q];
objFunction += var1 * var2 * var3 * var4; // Put a breakpoint on this line
Breakpoint on that line and ensure your other values are being set properly by hovering var1, var2 etc
are you assuming its int because %d? %d will work on a double or anything else too, and print nonsense all day long. A lot of new programmers assume d is for double, without looking the codes up.
I don't know because you won't answer my question.
%d is for INTEGERS (any).
try %1.10f for doubles (or floats or long doubles etc). 1.10 means 10 decimal places. 20 is more than most systems actually have so between 1.0 and 1.20 as you like it. There are also codes for scientific notation and more.
if its not a double/float/int type, tell me more.
printf uses a dumb pointer approach. whatever you stick in the variables, it takes a pointer to that address and then attempts to use that as if it were what you said it was. This can be useful to exploit, or it can cause bugs and crashes, depending on what you did to it. Mostly, you should stick to following the intentions of the tool until you understand it very well. And mostly, you should be using c++ tools, though I will use printf for bunches of doubles due to the formatting hassle of cout.