When you put:
if (abs(hot_plate_next[a][b] - hot_plate[a][b]) < 0.1) { update = false; }
inside the second nested for loop, you set "update" to false if the ANY of the cells has a difference of less than 0.1 between the current and previous checks, and not ALL cells as you wanted.
Update your code as follows:
bool update = false;
and
if (abs(hot_plate_next[a][b] - hot_plate[a][b]) > 0.1) { update = true; }
(I would put> =, but you said "so far no cell in the array will change by more than 0.1 degrees")
Edit as requested: to display the matrix cleanly, add the following line:
cout << "\n";
here:
for (int a = 1; a < array_size-1; a++) { for (int b = 1; b < array_size-1; b++) { hot_plate_next[a][b]=sum_cell(hot_plate_next, a,b); if (abs(hot_plate_next[a][b] - hot_plate[a][b]) > 0.1) { update = true; } hot_plate_next[a][b] = hot_plate[a][b]; cout << hot_plate[a][b] << " "; } cout << "\n"; // Add this line }
source share