ปัญหาโปรแกรมจับเวลา
#include<stdio.h> #include<conio.h> #include<windows.h> #include<time.h> #include <stdlib.h> void number0(); void number1(); void number2(); void number3(); void number4(); void number5(); void number6(); void number7(); void number8(); void number9();
void fun_hh(int x,int y); void fun_h(int x,int y); void fun_mm(int x,int y); void fun_ss(int x,int y); void fun_s(int x,int y); void fun_ms(int x,int y); void fun_mms(int x,int y); void delay(double mseconds); COORD coord={0,0}; void gotoxy(int x,int y) { coord.X=x; coord.Y=y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord); } short mms=0,ms=0,ss=0,s=0,m=0,mm=0,h=0,hh=0; main() { short start=1; short exit=0; char ch;
while(exit!=1)
{ // delay(100); gotoxy(20,9); printf("Start : 'S' Reset : 'R' Exit : 'Q'"); fun_hh(9,2); fun_h(15,2); gotoxy(21,3); printf("#"); gotoxy(21,5); printf("#"); fun_mm(23,2); fun_m(29,2); gotoxy(35,3); printf("#"); gotoxy(35,5); printf("#"); fun_ss(37,2); fun_s(43,2); gotoxy(49,3); printf("#"); gotoxy(49,5); printf("#"); fun_ms(51,2); fun_mms(57,2); if(_kbhit()) { ch=getch(); if(ch=='q'||ch=='Q') { exit=1; } else if(ch=='r'||ch=='R') { hh=0,h=0; mm=0,m=0; ss=0,s=0; mms=0,ms=0; } else if(ch=='s'||ch=='S') { start=0;
} } while(start!=1) {
gotoxy(20,9); printf(" Stop Enter key S "); mms++; delay(6);
if(_kbhit()) { ch=getch(); if(ch=='s'||ch=='S') { start=1; } } if(mms>9) { ms++; mms=0; { if(ms>9) { ms=0; s++; if(s>9) { ss++; s=0; if(ss>5) { ss=0; m++; if(m>9) { mm++; m=0; if(mm>5) { h++; mm=0; if(h>9) { hh++; h=0; } } } } } } } }
fun_hh(9,2); fun_h(15,2); gotoxy(21,3); printf("#"); gotoxy(21,5); printf("#"); fun_mm(23,2); fun_m(29,2); gotoxy(35,3); printf("#"); gotoxy(35,5); printf("#"); fun_ss(37,2); fun_s(43,2); gotoxy(49,3); printf("#"); gotoxy(49,5); printf("#"); fun_ms(51,2); fun_mms(57,2); } } } void fun_hh(int x,int y) { switch(hh) { case 0 :number0(x,y);break; case 1 :number1(x,y);break; case 2 :number2(x,y);break; case 3 :number3(x,y);break; case 4 :number4(x,y);break; case 5 :number5(x,y);break; case 6 :number6(x,y);break; case 7 :number7(x,y);break; case 8 :number8(x,y);break; case 9 :number9(x,y);break; } } void fun_h(int x,int y) { switch(h) { case 0 :number0(x,y);break; case 1 :number1(x,y);break; case 2 :number2(x,y);break; case 3 :number3(x,y);break; case 4 :number4(x,y);break; case 5 :number5(x,y);break; case 6 :number6(x,y);break; case 7 :number7(x,y);break; case 8 :number8(x,y);break; case 9 :number9(x,y);break; } }
void fun_mm(int x,int y) { switch(mm) { case 0 :number0(x,y);break; case 1 :number1(x,y);break; case 2 :number2(x,y);break; case 3 :number3(x,y);break; case 4 :number4(x,y);break; case 5 :number5(x,y);break; case 6 :number6(x,y);break; case 7 :number7(x,y);break; case 8 :number8(x,y);break; case 9 :number9(x,y);break; } } void fun_m(int x,int y) { switch(m) { case 0 :number0(x,y);break; case 1 :number1(x,y);break; case 2 :number2(x,y);break; case 3 :number3(x,y);break; case 4 :number4(x,y);break; case 5 :number5(x,y);break; case 6 :number6(x,y);break; case 7 :number7(x,y);break; case 8 :number8(x,y);break; case 9 :number9(x,y);break; } } void fun_ss(int x,int y) { switch(ss) { case 0 :number0(x,y);break; case 1 :number1(x,y);break; case 2 :number2(x,y);break; case 3 :number3(x,y);break; case 4 :number4(x,y);break; case 5 :number5(x,y);break; case 6 :number6(x,y);break; case 7 :number7(x,y);break; case 8 :number8(x,y);break; case 9 :number9(x,y);break; } } void fun_s(int x,int y) { switch(s) { case 0 :number0(x,y);break; case 1 :number1(x,y);break; case 2 :number2(x,y);break; case 3 :number3(x,y);break; case 4 :number4(x,y);break; case 5 :number5(x,y);break; case 6 :number6(x,y);break; case 7 :number7(x,y);break; case 8 :number8(x,y);break; case 9 :number9(x,y);break; } } void fun_ms(int x,int y) { switch(ms) { case 0 :number0(x,y);break; case 1 :number1(x,y);break; case 2 :number2(x,y);break; case 3 :number3(x,y);break; case 4 :number4(x,y);break; case 5 :number5(x,y);break; case 6 :number6(x,y);break; case 7 :number7(x,y);break; case 8 :number8(x,y);break; case 9 :number9(x,y);break; } }
void fun_mms(int x,int y) { switch(mms) { case 0 :number0(x,y);break; case 1 :number1(x,y);break; case 2 :number2(x,y);break; case 3 :number3(x,y);break; case 4 :number4(x,y);break; case 5 :number5(x,y);break; case 6 :number6(x,y);break; case 7 :number7(x,y);break; case 8 :number8(x,y);break; case 9 :number9(x,y);break; } }
void number0(int x,int y) { gotoxy(x,y); printf("#####\n"); gotoxy(x,y+1); printf("# #"); gotoxy(x,y+2); printf("# #"); gotoxy(x,y+3); printf("# #"); gotoxy(x,y+4); printf("#####"); } void number1(int x,int y) { gotoxy(x,y); printf(" #"); gotoxy(x,y+1); printf(" #"); gotoxy(x,y+2); printf(" #"); gotoxy(x,y+3); printf(" #"); gotoxy(x,y+4); printf(" #"); } void number2(int x,int y) { gotoxy(x,y); printf("#####"); gotoxy(x,y+1); printf(" #"); gotoxy(x,y+2); printf("#####"); gotoxy(x,y+3); printf("# "); gotoxy(x,y+4); printf("#####"); } void number3(int x,int y) { gotoxy(x,y); printf("#####"); gotoxy(x,y+1); printf(" #"); gotoxy(x,y+2); printf("#####"); gotoxy(x,y+3); printf(" #"); gotoxy(x,y+4); printf("#####"); } void number4(int x,int y) { gotoxy(x,y); printf("# #"); gotoxy(x,y+1); printf("# #"); gotoxy(x,y+2); printf("#####"); gotoxy(x,y+3); printf(" #"); gotoxy(x,y+4); printf(" #"); } void number5(int x,int y) { gotoxy(x,y); printf("#####"); gotoxy(x,y+1); printf("# "); gotoxy(x,y+2); printf("#####"); gotoxy(x,y+3); printf(" #"); gotoxy(x,y+4); printf("#####");
} void number6(int x,int y) { gotoxy(x,y); printf("#####"); gotoxy(x,y+1); printf("# "); gotoxy(x,y+2); printf("#####"); gotoxy(x,y+3); printf("# #"); gotoxy(x,y+4); printf("#####"); } void number7(int x,int y) { gotoxy(x,y); printf("#####"); gotoxy(x,y+1); printf(" #"); gotoxy(x,y+2); printf(" #"); gotoxy(x,y+3); printf(" #"); gotoxy(x,y+4); printf(" #"); } void number8(int x,int y) { gotoxy(x,y); printf("#####"); gotoxy(x,y+1); printf("# #"); gotoxy(x,y+2); printf("#####"); gotoxy(x,y+3); printf("# #"); gotoxy(x,y+4); printf("#####"); } void number9(int x,int y) { gotoxy(x,y); printf("#####"); gotoxy(x,y+1); printf("# #"); gotoxy(x,y+2); printf("#####"); gotoxy(x,y+3); printf(" #"); gotoxy(x,y+4); printf("#####"); }
void delay( double mseconds) { clock_t goal = mseconds + clock(); while (goal > clock()); }
|