Counter Problem

I want a line gap every 25 numbers printed, what I've written is being ignored. I'd like to know why.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

int main()
{
    int x;
    int counter;

    counter=0;

    for (x=0; x<=100; x++) {
    cout<< x<<"\n";

    counter++;
    if (counter==25) cout<< "\n";
    counter=0;}


    return 0;

}
Try the modulus operator
if(x%25 == 0)

As for your problem, only cout<< "\n";
is covered by the if statement and your counter is set to 0 at the end of every round
Last edited on
Edited version of code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;

int main()
{

    for (int x = 0; x <= 100; x++) {
    cout<< x<<"\n";

    
	if ((x == 25) || (x == 50) || (x == 75)) { cout<< "\n";}}
	
	while (true) {}


    return 0;

}
Why would you randomly throw in a while(true) in there?
Oh my bad, that's just my way of keeping the program open so I can see the results.
closed account (9wX36Up4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include<conio.h>

using namespace std;

int main()
{
    int x;
    int counter;

    counter=0;

    for (x=1; x<=100; x++) {
    cout<< x<<"\n";
    counter++;
    if (counter==25){
    cout<< "\n";
    counter=0;}//your mistake is after if u didn't use '{'
    }
    getch();
}
closed account (zb0S216C)
Creekist, your code is a clock-cycle rapist.

Anon, here you go my good man:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

int main()
{
    int Step( 25 );
    int Counter( 0 );

    for( int i( 1 ); i <= ( 100 / Step ); i++ ) 
    {
        for( int j( 1 ); j <= Step; j++ )
        {
            Counter++;
            std::cout << Counter << std::endl;
        }

        std::cout << std::endl << std::endl;
    }

    std::cin.ignore( std::numeric_limits< std::streamsize >::max( ), '\n' );
    return 0;

}

Wazzak
Last edited on
What's a clock cycle rapist?
while(true); is. It'll burn every little bit of CPU time it can get.
However, when the program is waiting for input as it does when using ignore(), it doesn't require any CPU time.
Interestingg, do you enjoy harassing people on the internet?
?
I feel like you're trolling my posts and harassing me. Please stop.
I feel like you're trolling my posts and harassing me. Please stop.

You're wrong. What the hell are you talking about anyway?
closed account (zb0S216C)
Creekist, unless you, as a person, take up clock-cycles. I was referring to your code, not you directly.

Wazzak
Last edited on
...which should be pretty obvious. If you think Framework called you a rapist, you're in serious need of a therapy.
Edit: or don't you know what a clock cycle is? Then see here:
http://en.wikipedia.org/wiki/Clock_rate
Last edited on
Actually Athar the cynicism in your post is directly what I'm referring too (therapy etc.) There is no need to be cynical on the internet the internet does not mandate it. You can be unique on the internet by being kind, bnot by being mean or some variation thereof. :)
You can act however you feel is right, but don't assume everyone has to act or think like you do.
No one was harassing you, so your comment was equally unnecessary.
Well there we go again. K nvm. Lawl
Topic archived. No new replies allowed.