Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
2

Timer cpp

darklordplati
darklordplati

I need to run a timer while the program is la running something else. When the timer stops, the program will stop as well

My code is showing errors.
int random() {
using namespace std;
int answer;
cout << iSecret;
chrono::steady_clock::time_point tend=chrono::steady_clock::now() + chrono::seconds(10);
while (tend < 10) {
cin >> answer;
if (answer == tend) {
money = money + 10;
} else {
money = money - 10;
}
cout << "you have ";
cout << money;
cout << "cash";
}
}

4 years ago
You are viewing a single comment. View All
1
CPPStudent7308
CPPStudent7308

@darklordplati
Okay, I see. What you need is a break command that tells the computer to go back to the main function when a certain function is done running. You can implement this at the end of your timer function so that when it breaks to main, there is nothing left in main to run, so the program stops. Does that make sense? (p.s. I do not know if this is cross platform. All I know is that it works in C++ at least)

4 years ago