#include<conio.h>
#include<process.h>
#include<stdio.h>
#include<windows.h>
int sun()
void gotoxy(int x, int y);
int EV(int i,int x,int y);
int h,m,s;
char ch='p';
void Z (int x,int y);
void O (int x,int y);
void T (int x,int y);
void TE (int x,int y);
void F (int x,int y);
void FE (int x,int y);
void S (int x,int y);
void SN (int x,int y);
void E (int x,int y);
void N (int x, int y);
void TN (int x,int y);
void AA (int x,int y);
void PP (int x,int y);
void MM (int x,int y);
void CC (int x,int y);
main()
{
int set;
void watch();
void main_menu();
main_menu();
watch();
while(1)
{
if(kbhit())
ch=getch();
if(ch=='s'||ch=='S')
break;
if(ch=='e'||ch=='E')
exit(0);
}
while(1)
{
watch();
sleep(1000);
if(kbhit())
ch=getch();
if(ch=='r'||ch=='R')
{
main_menu();
watch();
while(1)
{
if(kbhit())
ch=getch();
if(ch=='s'||ch=='S')
break;
if(ch=='e'||ch=='E')
exit(0);
}
}
else
if(ch=='p'||ch=='P')
while(1)
{
如果(的kbhit())
CH =的getch();
如果(CH == 's' 的|| CH == 'S')
破;
如果(CH == 'E' || CH == 'E')
出口(0);
如果(CH == 'R' || CH = = 'R')
{
CH = 'C';
MAIN_MENU();
观看();
} {{1} }}
否则
如果(CH == 'E' || CH == 'E')
出口(0);`
if(s!=59)
s++;
else
{
s=0;
if(m!=59)
m++;
else
{
m=0;
if(h!=12)
h++;
else
{
h=1;
}
}
}
}
}
void watch()
{
int ampm,AP,OS,TS,x,y;
` if (ampm!=112)`
` {`
` AP = 97;`
}`
else
{
AP=112;
}
system("cls");
`TS = h/10;`
` OS = h%10;`
` x =12;`
` y = 5;`
`EV(TS,x,y);`
`x+=6;`
` EV(OS,x,y);`
` x+=6;`
` CC(x,y);`
` TS = m/10;`
` OS = m%10;`
` x+=5;`
`EV(TS,x,y);`
`x+=6;`
` EV(OS,x,y);`
` x+=6;`
` CC(x,y);`
` TS = s/10;`
` OS = s%10;`
`x+=5;`
` EV(TS,x,y);`
`x+=6;`
` EV(OS,x,y);`
`x+=6; `
` if (h==12)`
if(AP == 112){
AP = 97;`
` else if (AP==97)`
` AP=112;`
` } `
if (AP==97)
AA(x,y);
else if (AP==112)
x + = 5; PP(x,y);
MM(x,y);`
printf("\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\tPress Key");
printf("\n\t\t\t\t\t\t\t---------");
printf("\n\t\t\t\t\t\t\ts -> Start");
printf("\n\t\t\t\t\t\t\tp -> Pause");
printf("\n\t\t\t\t\t\t\tr -> Reset");
printf("\n\t\t\t\t\t\t\te -> Exit");
void main_menu()}
{
int ampm;
system("cls");
printf("WELCOME TO THE TIME MACHINE!!");
printf("\nPlease input the desired time you want to travel to:");
printf("\nHour:");
scanf("%d",&h);
printf("\nMinute:");
scanf("%d",&m);
printf("\nSecond:");
scanf("%d",&s);
ampm=sun();
system("cls");
}
void Z (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 O (int x,int y)
{
gotoxy(x,y) ;printf("*** \n");
gotoxy(x,y+1);printf(" * \n");
gotoxy(x,y+2);printf(" * \n");
gotoxy(x,y+3);printf(" * \n");
gotoxy(x,y+4);printf("*****\n");
}
void T (int x,int y)
{
gotoxy(x,y) ;printf("***** \n");
gotoxy(x,y+1);printf(" * \n");
gotoxy(x,y+2);printf("***** \n");
gotoxy(x,y+3);printf("* \n");
gotoxy(x,y+4);printf("***** \n");
}
void TE (int x,int y)
{
gotoxy(x,y) ;printf("***** \n");
gotoxy(x,y+1);printf(" * \n");
gotoxy(x,y+2);printf(" *** \n");
gotoxy(x,y+3);printf(" * \n");
gotoxy(x,y+4);printf("***** \n");
}
void F (int x,int y)
{
gotoxy(x,y) ;printf("* * \n");
gotoxy(x,y+1);printf("* * \n");
gotoxy(x,y+2);printf("***** \n");
gotoxy(x,y+3);printf(" * \n");
`}
gotoxy(x,y+4);printf(" * \n");
{
void FE (int x,int y)
gotoxy(x,y) ;printf("***** \n");
gotoxy(x,y+1);printf("* \n");
gotoxy(x,y+2);printf("***** \n");
gotoxy(x,y+3);printf(" * \n");
gotoxy(x,y+4);printf("***** \n");
}
void S (int x,int y)
{
gotoxy(x,y) ;printf(" *** \n");
gotoxy(x,y+1);printf("* \n");
gotoxy(x,y+2);printf("***** \n");
gotoxy(x,y+3);printf("* * \n");
gotoxy(x,y+4);printf(" *** \n");
}
void SN (int x, int y)
{
gotoxy(x,y) ;printf("***** \n");
gotoxy(x,y+1);printf(" * \n");
gotoxy(x,y+2);printf(" * \n");
gotoxy(x,y+3);printf(" * \n");
gotoxy(x,y+4);printf(" * \n");
}
void E (int x,int y)
{
gotoxy(x,y) ;printf(" *** \n");
gotoxy(x,y+1);printf("* * \n");
gotoxy(x,y+2);printf("***** \n");
gotoxy(x,y+3);printf("* * \n");
gotoxy(x,y+4);printf(" *** \n");
}
void N (int x,int y)
{
gotoxy(x,y) ;printf(" *** \n");
gotoxy(x,y+1);printf("* * \n");
gotoxy(x,y+2);printf("***** \n");
gotoxy(x,y+3);printf(" * \n");
gotoxy(x,y+4);printf(" *** \n");
}
void AA (int x,int y)
{
gotoxy(x,y) ;printf(" *** \n");
gotoxy(x,y+1);printf("* * \n");
gotoxy(x,y+2);printf("***** \n");
gotoxy(x,y+3);printf("* * \n");
gotoxy(x,y+4);printf("* * \n");
}
void PP (int x,int y)
{
gotoxy(x,y) ;printf("***** \n");
gotoxy(x,y+1);printf("* * \n");
gotoxy(x,y+2);printf("***** \n");
gotoxy(x,y+3);printf("* \n");
gotoxy(x,y+4);printf("* \n");
}
void MM (int x,int y)
{
gotoxy(x,y) ;printf(" * * \n");
gotoxy(x,y+1);printf(" ** ** \n");
gotoxy(x,y+2);printf(" * * * \n");
gotoxy(x,y+3);printf(" * * \n");
gotoxy(x,y+4);printf(" * * \n");
}
void CC (int x,int y)
{
gotoxy(x,y) ;printf(" \n ");
gotoxy(x,y+1);printf(" ** \n");
gotoxy(x,y+2);printf(" \n ");
gotoxy(x,y+3);printf(" ** \n");
gotoxy(x,y+4);printf(" \n ");
}
int EV(int i,int x,int y)
{
switch(i)
{
case 0:
{
Z(x,y); break;}
case 1:
{
O(x,y); break;}
case 2:
{
T(x,y); break;}
case 3:
{
TE(x,y); break;}
case 4:
{
F(x,y); break;}
case 5:
{
FE(x,y); break;}
case 6:
{
S(x,y); break;}
case 7:
{
SN(x,y); break;}
case 8:
{
E(x,y); break;}
case 9:
{
N(x,y); break;}
}
}
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x; coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
int sun()
{
int key,ampm;
gotoxy(23,14);printf("\n Press A for AM");
gotoxy(27,15);printf("\n Press P for PM");
if(kbhit())
if(key=getch()=='a')ampm = 97;
if(key=getch()=='p')ampm = 112;
return ampm;
当我输入时间为上午11:59:59时,它将正常显示,并将在我开始时钟时间的下午12:00:00。但是当我在晚上11:59:59输入时,只显示M,当开始计时时,它将显示在上午11:59:59并将转到PM。 抱歉,编程很新。
答案 0 :(得分:0)
问题如下。
如果您的set变量包含除112以外的任何内容,那么您的AP将设置为97并正确处理为AM格式化。
但是!
即使您的设置等于112,也不要将AP变量设置为112。
代码中的简单修改可以解决您的问题:
if (set!=112)
{
AP = 97;
}
else
{
AP = 112;
}
这样,您可以将AP设置为112并在写入M之前正确写入P.