I'm trying to make a "Guess the Number" game where the user picks the HiddenNumber and the AI trys to guess the number. I relized that to do this like a normal person would, I need a line of code that will replicate what a Human would do to a std::cin (Type an Answer and it will exeucte)
#include <iostream>
#include <string>
void AI();
int HiddenNumber;
std::string AIPrefix = "(AI) ";
int main() {
while (true) {
std::cout << "Pick a number 1-100 that my coded AI will try to guess: ";
std::cin >> HiddenNumber;
if (std::cin.fail()) {
std::cout << "Enter an integer, try again.\n\n";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
else {
break;
}
}
std::cout << "\nBeyond this point dont answer anything, as its the AI's guessing turn.\n\n";
AI();
}
void AI() {
std::cout << "Enter a Guess 1-100: ";
// Line of code that replicates a user typing to a std::cin
return;
}
Example, if the HiddenNumber is 60, and the AI types 50, then it will say to low, etc. (Gives a simpler idea to what Im aiming for)