end while function

I'm trying to end this while loop by hitting ENTER key, just so i don't have exit the program by closing the program.
no i am not an idiot who doesn't know break, and i do not want the function to require a person at the console every time the loop needs to reoccur.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

void wait (int seconds){
    clock_t timer;
    timer = clock() + seconds * CLOCKS_PER_SEC ;
    while (clock() < timer) {}
}

int main(){
    int hours = 0, minutes = 0, seconds = 0;

    while (hours>=0){
        if( minutes < 10){
            cout << hours << ":0" << minutes << ":" << seconds << '\n';
        }
        else{
            cout << hours << ":" << minutes << ":" << seconds << '\n';
        }
        
        wait(1);
        
    ++seconds; 
    
    if(seconds == 60){ 
           
            seconds-= 60;
            
            ++minutes;
    }
        
    if(minutes == 60){

        minutes-=60;
        
        ++hours;
    }
     
}

    return 0;
}


i want this to function as a timer, and was wondering if some1 knows how to do this, because i have no clue.
note: this is on a mac so xcode is my ide.
It might be possible to do this with threads but other than that there is no way to do this in just standard C++. You might want to use some library like ncurses to do this.
Topic archived. No new replies allowed.