For loop

I want to create a for loop which contains an equation, where one variable changes each time the loop runs, and alos with an if statement to find a minimum value.
for (int i = 0; i < 8; i++)
{ float Ea = Ea + 10000;
float tempResult = differenceofsquares;
differenceofsquares += (k[i] - (A*exp(-Ea / (R*T[i]))))*(k[i] - (A*exp(-Ea / (R*T[i]))));


if (tempResult < differenceofsquares2)
differenceofsquares2 = tempResult;

Last edited on
Please use code tags when posting. Highlight the code section of your post and click the <> button to the right of the edit window.

float Ea = Ea + 10000; won't work because you can't define a variable in terms of itself. Also, Ea will be recreated each time you enter the loop. I think you want to define Ea before the loop, and increment it inside.

what is differenceofsquares2 vs differenceofsquares?
Topic archived. No new replies allowed.