简体   繁体   中英

Wondering why I'm getting the error “use of an undeclared identifier”

   // TODO: Calculate number of years until we reach threshold
   { 
    int years;
    while (ending_size>=starting_size)
    starting_size = starting_size + (starting_size/3) - (starting_size/4);
    years++;
    }
            {// TODO: Print number of years
            printf("Years: %i\n", years);
            }
}

When I run my code, it says "use of undeclared identifier "years", and I think it might be due to the way that I formatted my code. Thanks

It looks like you have {} around the code where years is declared. I think that's your problem. The { and } limit its scope.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM