赋值标志量时注意点

设置标志时,要随时注意该标志的状态变化状况,注意一定要确保该标志每次计算时可以回到最初状态。 

例:
      int test=1;
     do
    {
        test = 1;//注意一定不可以遗忘
        printf("请输入年月日(中间以空格符间隔) ");
        scanf(" %d%d%d",&year,&month,&day);
        if (year>2014||year<1864)
        {
            printf("输入年份错误,请更改! ");
            test = 0;
            continue;
        }
    }while (!test);
 
例2:
计算1!+2!+3!+……+n!的值
 for (int i=1; i<=n; i++)
    {
        result1=1;//注意使用result1后重新对其初始化
        for (int j = 1; j<=i; j++)
        {
            result1*=j;
        }
        result+=result1;
    }
原文地址:https://www.cnblogs.com/Alling/p/3971316.html