问题标题: 计时器2.0

1
1
方钰涵
方钰涵
新手守护
新手守护

@彭志杰  你发的计时器程序我把它改造了一下,你来试试!

按任意字母键就能结束响铃

#include <bits/stdc++.h>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
#include <winuser.h>
#include <winsock.h>
using namespace std;
int a, b, c; // hours, minutes, seconds
int main() {
    cout << "Please input the timekeeping, do not enter decimals:\n";
    cout << "Hours(The input number must smaller than 24):";
    cin >> a;
    cout << "\nMinutes(The input number must smaller than 60):";
    cin >> b;
    cout << "\nSeconds(The input number must smaller than 60):";
    cin >> c;
    cout << "OK now, timing starts\n";
    Sleep(2000);
    system("cls");
    cout << a << ":" << b << ":" << c << "\n";
    Sleep(1000);
    system("cls");
    while(1) {
        if(!a&&!b&&!c) break;
        if(!c&&b) c=60, b--;
        else if(!b&&a&&!c) c=60, b=59, a--;
        c--;
        cout << a << ":" << b << ":" << c << "\n";
        Sleep(1000);
        system("cls");
    }
    system("cls");
    while(!GetAsyncKeyState('A')&&!GetAsyncKeyState('B')&&!GetAsyncKeyState('C')&&!GetAsyncKeyState('D')&&!GetAsyncKeyState('E')&&!GetAsyncKeyState('F')&&!GetAsyncKeyState('G')&&!GetAsyncKeyState('H')&&!GetAsyncKeyState('I')&&!GetAsyncKeyState('J')&&!GetAsyncKeyState('K')&&!GetAsyncKeyState('L')&&!GetAsyncKeyState('M')&&!GetAsyncKeyState('N')&&!GetAsyncKeyState('O')&&!GetAsyncKeyState('P')&&!GetAsyncKeyState('Q')&&!GetAsyncKeyState('R')&&!GetAsyncKeyState('S')&&!GetAsyncKeyState('T')&&!GetAsyncKeyState('U')&&!GetAsyncKeyState('V')&&!GetAsyncKeyState('W')&&!GetAsyncKeyState('X')&&!GetAsyncKeyState('Y')&&!GetAsyncKeyState('Z')){
        system("cls");
        cout << "Timing ends!";
        cout << char(7);
        Sleep(1000);
    }cout << "Timing ends!";
    return 0;
}

 


0
0
于行衍
于行衍
新手天翼
新手天翼

#include <bits/stdc++.h>

#include <windows.h>

#include <stdlib.h>

using namespace std;

int a, b, c; // hours, minutes, seconds

int main() {

cout << "Please input the timekeeping, do not enter decimals:\n";

cout << "Hours(The input number must smaller than 24):";

cin >> a;

cout << "\nMinutes(The input number must smaller than 60):";

cin >> b;

cout << "\nSeconds(The input number must smaller than 60):";

cin >> c;

cout << "OK now, iming starts\n";

system("cls");

cout << a << "hours " << b << "minutes " << c << "seconds\n";

Sleep(1000);

system("cls");

while(1) {

if(!a&&!b&&!c) break;

if(!c&&b) c=60, b--;

else if(!b&&a&&!c) c=60, b=59, a--;

c--;

cout << a << "hours " << b << "minutes " << c << "seconds\n";

Sleep(1000);

system("cls");

}

system("cls");

cout << char(7) << "Timing ends!";

return 0;

}

0
我要回答