Got a quick question on while loop.

let's say there's an array of 1 by 12

Bruce = (1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4)

i want to write a while loop that will display the column number whenever the number changes

what i wrote is this

int n;
for (Bruce(n + 1) = Bruce(n))
{
n = n + 1;
}
Bruce (n);

\\ here's the place where i'm stuck, I dont' know how to loop it so it will display 3 and 4. right now my code only stop on the first change of number.
Last edited on
1
2
3
4
5
6
7
for (int i=1; i<12; i++)
{
  if (Bruce[i] != Bruce [i-1])
  {  cout << "Change at col " << i << endl;
      cout << "Old val = " << Bruce[i-1] << endl;
      cout << "New val = " << Bruce[i] << endl;}
}
Last edited on
Topic archived. No new replies allowed.