How do I write a program to count from 1 to 100 in 3 seconds?? I know how to do the first part of counting 1 to 100, but got no idea how to write it to be executed in 3 seconds.
The Sleep function does this for you. You need to include windows.h for the sleep function to work.
It goes in miliseconds (which is 1000 btw, not 100)
Basically I divided 3000 (3 seconds) by 100 to get 30. It should count once every 30 miliseconds.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <windows.h> //for sleep function to work
usingnamespace std;
int main()
{
for (int i = 1; i <= 100; ++i)
{
cout << i << endl;
Sleep(30);
}
return 0;
}