如何通过C++编写一个简单的倒计时程序?

  #include

  #include

  #include

  #include

  using namespace std;

  int main() {

  int hours, minutes, seconds, totalSeconds;

  cout << "Enter hours: ";

  cin >> hours;

  cout << "Enter minutes: ";

  cin >> minutes;

  cout << "Enter seconds: ";

  cin >> seconds;

  totalSeconds = hours * 3600 + minutes * 60 + seconds;

  for (int i = totalSeconds; i >= 0; i--) {

  int h, m, s;

  h = i / 3600;

  m = (i % 3600) / 60;

  s = i % 60;

  cout << h << ":" << m << ":" << s << endl;

  Sleep(1000);

  system("cls");

  }

  cout << "Time is up!" << endl;

  return 0;

  }登录后复制