I want to know how I can create a countdown that can be stopped when the user inputs something such as writing a specific sentence.
In my case I want to do something like a 'Simon says' game. Simon says 'UP' and so you have to type in UP within a time limit of two seconds. If you type anything that is not 'UP' the countdown stops and it prints out that you fail whilst if you do type 'UP' it breaks the countdown and says you win. You are also notified that you fail when the countdown reaches zero and you haven't typed anything.
Here's what I've written so far:
#include <iostream>
#include <string>
#include <cmath>
#include<windows.h>
using namespace std;
int main() {
string answer;
int success = 0;
int counter = 0;
cout << "Simon says: UP" << endl;
for (int i = 2; i > 0; i--) {
cin >> answer;
if (answer == "UP") {
cout << "You win" << endl;
break;
}
else {
cout << "You lose" << endl;
}
}
return 0;
}