looping through a vector and pausing after a number of loops

Hi all.

I want to be able to loop through a vector which displays customer details. The problem is, when the vector grows and grows, many of the details will obviously not be in view as it will just loop until the end.

I basically want to be able to print 5 customers out and then use system("PAUSE") or something, so the user has to press enter after every 5 customers to go on and display the next 5 and so on until the end of the vector.

This is my loop.

for(int i = 0; i < custVec.size(); i++)
{
custVec[i].print();
}
Try adding this:
if (!(i%5))system("PAUSE");
You could use the modulus operator to determine even multiples of 5 and pause then. Below I add 1 to i because i starts at 0.
1
2
3
4
5
6
7
8
for(int i = 0; i < custVec.size(); i++)
{
    custVec[i].print();
    if( ((i+1) % 5) == 0 )
    {
        // do your pause
    }
}
Bazzy, you beat me to it...
That worked great! thank you very much! :D
@seymore15074
Those things happen frequently... :^︴
You can find (many) other methods here: http://www.cplusplus.com/forum/beginner/1988/
Topic archived. No new replies allowed.