#include <iostream>
#include <future>
#include <thread>
#include <exception>
using namespace std;

int main() {
    promise<int> score_promise;
    future<int> score_future = score_promise.get_future();

    jthread t {
        [&score_promise]() {
            string line;
            int attempts = 0;
            cin.exceptions(ios::failbit | ios::badbit);
            try {
                do {
                    cout << "Guess my word: ";
                    getline(cin, line);
                    ++attempts;
                } while (line != "banana");
                score_promise.set_value(attempts);
            } catch (...) {
                score_promise.set_exception(current_exception());
            }
        }
    };

    try {
        int final_score = score_future.get();
        cout << "It took you " << final_score << " attempts!\n";
    } catch (const exception& e) {
        cout << "Exception from worker thread: " << e.what() << '\n';
    }
}