Undeclared identifier p in for loop [closed]

What would be the solution for this even though i already declared i as an int in the for loop?

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    int length;
    do
    {
        length = get_int("Length: ");
    }
    while (length < 1);

    int twice[length];
    
    for (int p = 0; p < length; p++);
    {
        twice[p] = 2 * twice[p - 1];
        printf("%i\n", twice[p]);
    }
}

  • 1

    You have an extra ; before the for loop body.

    – 

  • 1

    OT: When the ; problem is fixed, what is the value of p in twice[p - 1] on the first iteration?

    – 

Leave a Comment