S
S
Sergey Komarov2021-10-21 16:32:48
C++ / C#
Sergey Komarov, 2021-10-21 16:32:48

How to combine different blocks of code in one place?

I'm starting to learn C++. I don't understand how to combine different lines of code output text and countdown after?

After outputting this code

#include "stdafx.h"
#include <iostream>
#include <cstdlib> // для system
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
  setlocale(LC_ALL, "Russian");
  cout << "Форматирование жёсткого диска HDD запущено" << endl;
    system("pause"); // Только для тех, у кого MS Visual Studio
  return 0;
}

Need to start the countdown
for (int i = 60; i > 0; i--)
    {
        cout << i << endl;
        Sleep(1000);
    }


And then the output of the text
"Formatting the hard disk HDD is completed"
I do not understand how to combine this.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ronald McDonald, 2021-10-21
@Zoominger

cout <<  "Осталось " << i << " секунд..." << endl; //перед sleep

Well, at the end:
cout << "Форматирование жёсткого диска HDD завершено" << endl

K
K1ingleonide, 2021-10-21
@K1ingleonide

#include "stdafx.h"
#include <iostream>
#include <cstdlib> // для system
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
  setlocale(LC_ALL, "Russian");
  cout << "Форматирование жёсткого диска HDD запущено" << endl;
  for (int i = 60; i > 0; i--)
  {
    cout << i << endl;
    Sleep(1000);
  }
  // system("pause"); // Только для тех, у кого MS Visual Studio
  return 0;
}

Before returning, it was necessary to insert the necessary code, if it is necessary that after the program is completed the console does not close under Windows, then uncomment system("pause")
1. Entry point - _tmain
2. setlocale sets the locale of the program
3. Displaying the message "HDD formatting is started " to the console
4. Entering the loop
4. 1 Printing variable i to the console
4. 2 Stopping the thread for 1000 ms

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question