Aを3秒表示させ、その後Bを7秒表示させ、それを繰り返すプログラムを書きたいのですが
3:7に分けるにはどうしたら良いのですか?
比率について
-
たかぎ
Re:比率について
多くの環境(ただしホスト環境限定)では、
ただし、これが期待しているものかどうかまでは知りません。
#include <stdio.h>
#include <time.h>
int main()
{
clock_t t;
setbuf(stdout, NULL);
for (;;)
{
fputs("\rA", stdout);
t = clock();
while ((clock() - t) / CLOCKS_PER_SEC < 3)
;
fputs("\rB", stdout);
t = clock();
while ((clock() - t) / CLOCKS_PER_SEC < 7)
;
}
return 0;
}
で大丈夫かと思います。ただし、これが期待しているものかどうかまでは知りません。
-
lbfuvab
Re:比率について
眠いので我ながらヘンなプログラムですが
/***************************************
* *
* PCを起動してから10秒未満の時と *
* 49.7日起動させている時の動作は *
* 動作は良く分からない。 *
* *
* *
***************************************/
#include<stdio.h>
#include<windows.h>
int main(){
DWORD dwCount=GetTickCount()-10000;
while(1){
while(GetTickCount()-dwCount<7000); //7秒の計測
dwCount=GetTickCount();
printf("A\r");
Sleep(2500); //2.5秒眠らす
while(GetTickCount()-dwCount<3000); //3秒の計測
dwCount=GetTickCount();
printf("B\r");
Sleep(6500); //6.5秒眠らす
}
return 0;
}