int n, k, q; cin>>n>>k; //read the number of stories and eggs string response; while(response != "exit") { cout << "query " << n/6 << "\n"; //can also use endl for newline cout.flush(); cin >> response; if(response == "broke") q=n/6; if(q!=0) { for i in range } else { //in case you've found the answer cout << "answer " << x << "\n"; cout.flush(); cin >> response; //the response is going to be "exit" }