To form counter of N element
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: To form counter of N element

  1. #1
    Join Date
    May 2012
    Posts
    4

    To form counter of N element

    Hi,

    Can anyone let me know how can i form a counter of say 30 elements so that to meet following requirement,

    I need to access 5 elements out of 30 elements and out of these 5 elements once the one value is printed (i.e now access for remaining 4 element will be left) other one should get added immediately to this 5 element set, from remaining total 25 elements. In this way 5 element count will be there always.

    I am trying this as follows, by forming vector of 30 elements accessing its 5 elements as,
    for (iter = vector1.begin(); it < vector1.end();it++)
    {
    for(int count = 5; count >= 1 ; count--)
    {
    cout << "Print value<" <<count<<"> : "<< *it <<endl;
    it++;
    }
    }

    This displays 5 elements at a time but counter "count" waits for to finish off its remaining 4 elements however i want to maintain this counter to 5 elements always.

    Appreciate any help in this.

    Thanks.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,418

    Re: To form counter of N element

    1) Please use code tags when posting code.

    2)
    Code:
    for (iter = vector1.begin(); it < vector1.end();it++)
    {
       for(int count = 5; count >= 1 ; count--)
       {
           cout << "Print value<" <<count<<"> : "<< *it <<endl;
           it++; 
       }
    }
    What is "it"? It isn't declared anywhere.

    If you're typing your code into the message, don't do it. Copy and paste your code from your code editor into the message. I don't know if "it" is an iterator that was declared before and you're erroneously using it in the loop or if you made a typing error.
    I need to access 5 elements out of 30 elements and out of these 5 elements once the one value is printed (i.e now access for remaining 4 element will be left) other one should get added immediately to this 5 element set, from remaining total 25 elements. In this way 5 element count will be there always.
    I barely understood any of your requirements. How do you determine which element to choose from the 30 elements? Every fifth one? A random element?

    Maybe you should post an illustration using just 10 numbers, and what you're trying to do.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center