error with my for loop?

This is a discussion on error with my for loop? within the C Programming forums, part of the General Programming Boards category; figured it out, i was putting , instead of ;...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    20

    error with my for loop?

    figured it out, i was putting , instead of ;
    Last edited by rs07; 07-25-2008 at 08:16 PM.

  2. #2
    Registered User
    Join Date
    Jul 2008
    Posts
    1
    Quote Originally Posted by rs07 View Post
    Code:
    int main(void) {
    
    for(i = 5, i > 0, i--)
    {
    square = n * n;
    cube = n * n * n;
    quartics = n * n * n * n;
    square_root = sqrt(n);
    cube_root = cbrt(n);
    quartic_root = sqrt(sqrt(n));
    printf("%f\n", square_root);
    printf("%f\n", cube_root);
    printf("%f\n", quartic_root);
    return;
    }
    return(0);
    }
    its giving me an error at compile saying:

    Code:
    main.c: In function 'main':
    main.c:16: error: expected ';' before ')' token
    main.c:16: error: expected expression before ')' token
    whats going on?
    First, you need to declare 'i' at the start of main, so

    int main() {

    int i;

    next, in your for loop, there should be ';' instead of commas.

    for(i = 5, i > 0, i--) ---> for(i = 5; i > 0; i--)

    Give that a go.

Popular pages Recent additions subscribe to a feed

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21