ouput of even integers

okay, I want to output the even integers rom 2 to 100 and I will put my code on here (since everyone barks at me) what is wrong with it.

counter = 2;

Do {
if ( counter % 2 == 0 )
printf( "%d
", counter );

counter += 2;
} While ( counter < 100 );

I cant find the problem, thanks

Comments

  • [b][red]This message was edited by stober at 2005-6-30 19:32:21[/red][/b][hr]
    : okay, I want to output the even integers rom 2 to 100 and I will put my code on here (since everyone barks at me)

    [blue]everyone "barks" at you because we are not mind readers and misplaced our crystal balls. We can't help you if we know nothing about what you did.[/blue]

    what is wrong with it.
    :
    [code]
    : counter = 2;
    :
    : Do {
    : if ( counter % 2 == 0 )
    : printf( "%d
    ", counter );
    :
    : counter += 2;
    : } While ( counter < 100 );
    :
    : I cant find the problem, thanks
    :
    [/code]

    You didn't specify the proglem. Since you are incrementing the counter by 2 you don't need to use the mod operator because it will always be even numbers.

    The only thing I see that is really wrong is that, if you want to also print the value 100, you need to change the while statement
    [code]
    { while( counter [red]<= 100[/red]);
    [/code]




  • : what is wrong with it.
    : :
    : [code]
    : : counter = 2;
    : :
    : : Do {
    : : if ( counter % 2 == 0 )
    : : printf( "%d
    ", counter );
    : :
    : : counter += 2;
    : : } While ( counter < 100 );
    : :
    : : I cant find the problem, thanks
    : :
    : [/code]
    :
    As someone replied in a previous post, keywords do not get capitalized.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion