Можно ли проверить ввод в строковом формате? [дубликат] ⇐ C++
-
Anonymous
Можно ли проверить ввод в строковом формате? [дубликат]
The code below is the module that is supposed to check if another game should be played. However, even when typing yes or no, it still detects newGame as false, thus causing the while loop to iterate indefinitely regardless of input. What is the issue?
string askNewGame() { //Declare variable to store whether to run another game. string newGame = "no"; //Ask if the program should run another game. cout > newGame; //Ensure yes or no are entered. while (newGame != "yes" || "no") { cout > newGame; } return newGame; }
Источник: https://stackoverflow.com/questions/780 ... ing-format
The code below is the module that is supposed to check if another game should be played. However, even when typing yes or no, it still detects newGame as false, thus causing the while loop to iterate indefinitely regardless of input. What is the issue?
string askNewGame() { //Declare variable to store whether to run another game. string newGame = "no"; //Ask if the program should run another game. cout > newGame; //Ensure yes or no are entered. while (newGame != "yes" || "no") { cout > newGame; } return newGame; }
Источник: https://stackoverflow.com/questions/780 ... ing-format
Мобильная версия