简体   繁体   English

想知道为什么我收到错误“使用未声明的标识符”

[英]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. {}限制了它的 scope。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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