#include <bits/stdc++.h>
#include<windows.h>
using namespace std;
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
int x,f,m,h;
int main();
void mb(){
int xs=0,fz=0,ms=0,hs=0;
while(!KEY_DOWN(MOUSE_EVENT)){
if(hs==10){
ms++;
hs=0;
}else if(ms==60){
fz++;
ms=0;
}else if(fz==60){
xs++;
fz=0;
}
cout<<"============"<<endl;
cout<<'|';
printf("%02d:%02d:%02d.%1d", xs, fz, ms, hs);
cout<<'|'<<endl;
cout<<"============"<<endl;
_sleep(65);
system("cls");
hs++;
}
}
void jsq(){
int xs,fz,ms;
cout<<"输入时间:";
cin>>xs>>fz>>ms;
while((xs!=0||fz!=0||ms!=0)&&!KEY_DOWN(MOUSE_EVENT)){
if(ms==-1){
fz--;
ms=59;
}else if(fz==-1){
xs--;
fz=59;
}
cout<<"=========="<<endl;
cout<<'|';
printf("%02d:%02d:%02d", xs, fz, ms);
cout<<'|'<<endl;
printf("==========");
_sleep(970);
system("cls");
ms--;
}
if(xs==0&&fz==0&&ms==0) cout<<"\a";
}
int main(){
cout<<"欢迎来到我的c++计时器";
_sleep(1000);
system("cls");
int js;
cout<<"输入形式,1秒表,2计时器,3退出";
cin>>js;
if(js==1){
mb();
}else if(js==2){
jsq();
}else if(js==3){
exit(0);
}
system("cls");
main();
return 0;
}
1.美化了页面
运行效果
屏幕录制 2023-09-10 062553