Hey! I'm trying to do a while loop within a for loop. However whenever I run the program, it only does the 1st iteration of the for loop, and then exits :( I don't understand why the while loop is not running for all 120 instances of 'i'.
Thanks :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
for (int i = 0; i < 120; i++)
{
while (n < 1000 && DMMODELArray[i] < DMArray[i] )
{
n = n + 1;
delta_x = delta_x +.001;
delta_y = delta_y +.001;
delta_z = delta_z +.001;
double x = XArray[i] * delta_x;
double y = YArray[i] * delta_y;
double z = ZArray[i] * delta_z;
double ne = .025;
//double ne = A + B*exp(-abs(z)/C);
DMMODELArray[i] = 0 + DMMODELArray[i] + ne*abs(z);
DMODELArray[i] = 0 + DMODELArray[i] + delta_z;
cout << z << " " << i << " " << n << " " << ne << " " << DMODELArray[i] << " " << DArray[i] << " " << DMMODELArray[i] << " " << DMArray[i] << "\n";
}
}
The while loop runs until this (n < 1000 && DMMODELArray[i] < DMArray[i] )
is not true.
Second time round the for loop:
What's the status of (n < 1000 && DMMODELArray[i] < DMArray[i] )? How do you know it's true the next time? I see you're not resetting the value of n. If n finishes at over a thousand, the while loop will never run again.