运行结果 2:00一次,后面 1:00 1:00 1:00循环,没有1:59
#include
#include
#include
int main()
{
int a,b;
a=120;b=a%60;
while(a>=0)
{
if(b>=0 && b<10)
{
system("cls");
printf("%d:0%d",a/60,b);
Sleep(1000);
}
else
{
system("cls");
printf("%d:%d",a/60,b);
Sleep(1000);
}
a=a-1;
}
system("pause");
return 0;
}
如果,我不要b,直接将a%60代入,倒是正常了。
如果我删掉中间的判断条件,剩下
system("cls");
printf("%d:0%d",a/60,b);
Sleep(1000);
也是一样的不正常。说明不是判断条件导致错误的。而是b和a%60的关系,b=a%60。a=120;b=a%60;即b=0?
额,提问到这里,已找到答案。
问题出在b=a%60;
放错位置了,放这里,b的值就是固定的了,但它是个变量。
然后我把它放while下面花括号里了,运行正常了。