I am making a Text RPG in C++ as a little project. However, I am having trouble getting my function to repeat if the user inputs "No" or an invalid input.
This is my function:
void name_type() {
bool running = true;
system("CLS");
while (running == true) {
std::string name, option;
std::cout << "What is your name?\n";
std::getline(std::cin, name);
// Up to here is not repeated.
system("CLS");
std::cout << "Are you sure this is your name?\n\nType 'Yes' if so.\nElse, type 'No'.\n";
std::cin >> option;
system("CLS");
if (option == "Yes" || option == "yes") {
std::cout << "Hello, " << name << "!\n";
running = false;
}
else if (option == "No" || option == "no") {
continue;
}
else {
continue;
}
}
}
The problem is that when I go through the function, it will only repeat anything after the comment if I type "no". If, however I type "yes", it works fine.
Can anyone explain what is happening, and how to fix it?
std::cin >> option;there is still a\nin the stream