Time delay
#include <iostream>
#include <iomanip>
int main () {
int total_row, total_column;
std::cout << "Enter number of rows in a matrix: ";
std:: cin >> total_row;
std::cout << "Enter number of columns in a matrix: ";
std::cin >> total_column;
std:: cout << "You have set a " << total_row << " x " << total_column << " matrix" << std::endl;
int matrix [total_row][total_column];
srand ((unsigned)time(NULL));
for (int row = 0; row < total_row; row++) {
for (int column = 0; column < total_column; column++) matrix[row][column] = std::rand() % 100;
}
for (int row = 0; row < total_row; row++) {
for (int column = 0; column < total_column; column++) std::cout << std::setw(5) << std::right << matrix[row][column];
std::cout << '\n';
}
return 0;
}
/ waiting.cpp -- using clock() in a time-delay loop
#include <iostream>
#include <ctime> // describes clock() function, clock_t type
int main()
{
using namespace std;
cout << "Enter the delay time, in seconds: ";
float secs;
cin >> secs;
clock_t delay = secs * CLOCKS_PER_SEC; // convert to clock ticks
cout << "starting\a\n";
clock_t start = clock();
while (clock() - start < delay ) // wait until time elapses
; // note the semicolon
cout << "done \a\n";
return 0;
}