int n, k; 2 cin>>n>>k; //read the number of stories and eggs 3 4 string response; 5 while(response != "exit") { 6 cout << "query " << x << "\n"; //can also use endl for newline 7 cout.flush(); 8 9 cin >> response; 10 if(response == "broke") k--; 11 12 if(!sureAboutAnswer) { //perhaps you need more information 13 cout << "query " << x << "\n"; 14 cout.flush(); 15 16 cin >> response; 17 if(response == "broke") k--; 18 } 19 else { //in case you've found the answer 20 cout << "answer " << x << "\n"; 21 cout.flush(); 22 cin >> response; //the response is going to be "exit" 23 } 24 }