Good Morning,
This is a bit of a double question thread. First what i have done is written a basic stop watch program, it runs through the loops and iterates the time on screen.
My first question is this: is there some way to leave the program listening for user input to stop or reset the time or to exit the program?
Secondly i used the system("CLS")
to clear the previous count every time, i am under the understanding that this is not portable and not a good way to get the desired result. Is there some other way to have the cout of time to overwrite the last cout?
here is my code:
#include <iostream>
#include <cstdlib>
#include <windows.h>
using namespace std;
void stop_watch();
int main() {
stop_watch();
cin.get();
return 0;
}
void stop_watch() {
int hour = 0, min = 0, sec =0;
for (hour = 0; hour <= 1; hour++){
for (min = 0; min < 61; min++){
for (sec = 0; sec < 61; sec++){
Sleep(1000);
system("CLS");
cout << hour << ":" << min << ":" <<sec;
}
}
}
}
The system("CLS")
isn't a huge deal as it works for my situation right now, however in the spirit of doing things properly i would love to hear peoples ideas on this.
thanks