what's wrong with this simple code


for ( x = .000001; x <= .001; x += 2)
printf ( "%.7f
", x );


??

Comments

  • :
    : for ( x = .000001; x <= .001; x += 2)
    : printf ( "%.7f
    ", x );
    :
    :
    : ??
    :
    Well for one thing it will only ever loop once, making it a non-loop. try to figure out why. Look inside for(), for the reason.

    As per usual you don't specify where you are stuck. Is it a syntax error or is the output not what you expected?
  • syntax error, something is wrong
  • : :
    : : for ( x = .000001; x <= .001; x += 2)
    : : printf ( "%.7f
    ", x );
    : :
    : :
    : : ??
    : :
    : Well for one thing it will only ever loop once, making it a non-loop. try to figure out why. Look inside for(), for the reason.
    :
    : As per usual you don't specify where you are stuck. Is it a syntax error or is the output not what you expected?
    :
    I am pretty sure i know what the problem is, but it is hard to be 100%. Did you declare x? What type is it? What are the syntax errors. The compiler doesn't print out syntax errors for nothing, it tells you exactly what is wrong. It just takes a little effort to understand them sometimes.
  • : : :
    : : : for ( x = .000001; x <= .001; x += 2)
    : : : printf ( "%.7f
    ", x );
    : : :
    : : :
    : : : ??
    [blue]
    x must be of type float or double. Also, you
    cant/shouldnt compare doubles with integers like
    that. It should be:[/blue][code]
    foat x=0.0f;
    for ( x = .000001f; x <= .001f; x += 2.0f)
    printf ( "%.7f
    ", x );
    [/code]
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