I have a question that has evolved from one of my previous (Conditionally Breaking A Long Sequence Of Inputs?), but so far, no one has been able to give me a satisfactory answer, and all my efforts have failed.
I am trying to allow the user to break early from entering input if they don't need to. i.e., for the code below:
cout << '\n' << "Monster A's name is: ";
cin >> nameA;
cout << '\n' << "Monster A rolled: ";
cin >> rollM_A;
cout << '\n' << "Monster A's Dex is: ";
cin >> DexA;
cout << '\n' << "Monster A's Mod is: ";
cin >> ModA;
cout << '\n' << "Monster A's Level is: ";
cin >> LvlA;
//etc.
Up to 12 monsters are actually supported. If the user wants to use only, say, 3-4 of them, I'd like them to be able to skip the rest and save themselves a lot of keystrokes. I've already made sure to initialize all the variables to 0, and have a function to remove 0 elements from the storage vector later. All that's missing is getting away from this input chain. I have tried various forms of a while loop wrapping, like this:
while(cin.get() != '#') {
cout << '\n' << "Monster A's name is: ";
cin >> nameA;
//etc...
}
But upon entering the desired character, the code simply outputs all the prompts ("Monster A's name is:" , etc.) over and over again, without moving on or accepting further input. It's like the code is stuck in an infinite loop, even though it should be leaving the loop on # input.
Any ideas? Been really stuck on this for a while and would be very grateful if anyone could offer an alternate solution, or at least let me know the flaw in my own.
Thanks!