I am having a hard time creating a working C++ timer. I am just doing this for fun to see if I can. What it shouulld do is ask for an amount of minutes, and then cout each passing minute until the timer is up.
What it is doing though is only counting down twice and then stopping. It seems like the "endl" is not triggering the "cin.get()" like I would expect. Any advice on how I could do this better?
#include <iostream>
#include <ctime>
usingnamespace std;
void countdown (int);
int main()
{
cout << "How many minutes until your break is over?: ";
int minutes;
cin >> minutes;
countdown(minutes);
cout << endl << endl << "COUNTDOWN IS OVER!!!!\a";
cin.get();
}
void countdown(int n)
{
int delay = n;
int i = n;
clock_t time1 = clock();
while ((clock() - time1)/CLOCKS_PER_SEC < delay*60)
{
int delay2 = 60; //Delay in seconds until the next time a number is displayed on screen
clock_t time2 = clock();
cout << endl << i;
i--;
cin.get();
while ((clock()-time2)/CLOCKS_PER_SEC < delay2);
}
}