0

Hi folks,

I want to count the number of times elements in the array 'store' occurs. I have gone this far. What I want is to count the number of times the elements occurs like if 2 is occurring then it will begin with one, if again 2 is occurring, counter will be two and if some other number like 3 is occurring, counter will be again one and if again 2 occurs, counter should be 3 and so on. But this is what is happening in this code:
2 counter=1
2 counter=2
2 counter=3
3 counter=3 //this should be one
4 counter=3 //this should be one
4 counter=4 //this should be two
2 counter=4 //this should be four
3 counter=4 //this should be two

Can someone please provide the right steps from here.
Thanks

for(r=0;r<1;r++)
{
  if(dis==store[r])
  {
    counting++;
    ct=counting;
    for(g=0;g<50;g++)
    {
    if(dis==store[g])
    {
      ct++;
      ct=0;
    }
    }
  }
  else
  { 
    counting1=1;
    store[r]=dis;
  }
}
2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by gusano79
0

You only have one counter. If you want to count different values in the array, you need a counter for each value.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.