Skipping a line after a certain number of terms?

I am doing a loop where it adds one to the value of a number and prints it but I need it to skip after it prints every 5th term how would I do that?

And also how would I do it so that it prints first 1 term skips a line, then 2 skips a line, then 3 skips a line, etc?


1
2
3
4
5
6
7
8
9
10
11
12
int x=0, minNum=0, maxNum=0;
cout<<"Enter min number:\n";
cin>>minNum;

cout<<"Enter max number:\n";
cin>>maxNum;
for(x=minNum;x<maxNum;x++){

cout<<minNum<<", ";
minNum++;
}
return 0;
I am doing a loop where it adds one to the value of a number and prints it but I need it to skip after it prints every 5th term how would I do that?

You can use the modulo operator for that: if (x%5!=0)cout << something;

And also how would I do it so that it prints first 1 term skips a line, then 2 skips a line, then 3 skips a line, etc?

Have a counter variable and a variable holding the current number you want to count towards.
But what happens if x=minNum and minNum starts of divisible by 5, so say minNum = 10 it would print 10 then skip a line, I'm trying to get it so it prints like 10,11,12,13,14 then skips, so after every five terms
Ok, I did make a post here earlier, but I was wrong, lol.

This is how I coded it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
int _tmain(int argc, _TCHAR* argv[])
{
    int min = 0;
    int max = 0;

    bool firstRunThroughLoop = false;

    std::cout << "Please enter the lowest number: ";
    std::cin >> min;

    /* in the initial entry of min is divisible by 5 */
    /* set the bool to true */
    if( ! ( min % 5 ) )
        firstRunThroughLoop = true;

    std::cout << "Please enter the highest number: ";
    std::cin >> max;

    for( int i = min; min < max; i++ )
    {
        /* if the initial entry of min was divisible by 5 */
        /* cout the value and set the bool to false */
        /* so that it wont run through this again */
        if( firstRunThroughLoop )
        {
            firstRunThroughLoop = false;
            std::cout << min << "\n";
        }

        if( i % 5 )
            std::cout << min << "\n";

        min++;
    }
}
Topic archived. No new replies allowed.