1 2 3 4 5 6 7 8
|
//function Ask()
std::vector <char> GuessVector = StringToVector(GuessString);
if (CheckNumbers(GuessVector) == false) {
std::cout << "Not an isogram.\n\n";
Ask(); //discard the returned value
}
return GuessVector; //return the old value
|
in case the user's input is invalid, you do ask them again but you return the old one
to clarify, here's an example run
$ gdb a.out
(gdb) break Logic(std::vector<char, std::allocator<char> >)
(gdb) run
...
Guess the 4 digit isogram: 1111
Not an isogram.
Guess the 4 digit isogram: 1234
Breakpoint 1, Logic (GuessVector=std::vector of length 4, capacity 4 = {...}) at foo.cpp:129
129 int Bulls = CheckBulls(GuessVector);
(gdb) print GuessVector
$1 = std::vector of length 4, capacity 4 = {49 '1', 49 '1', 49 '1', 49 '1'} |
notice that Logic gets the invalid {1,1,1,1} vector
I don't understand why you launch a recursive call instead of simply looping (same thing you are doing in `PlayGame()' and `HiddenNumberGenerator()')
some other things in no particular order:
- ¿why is Logic() in charge of program termination? (I had to search for exit() in order to find this)
- don't make HiddenNumber a global variable
- comment your code (make it self-commenting). In CheckNumbers() you are checking repetitions, should know that at first glance (sure, can read the code, ¿but is your code correct?)
- variable names should be meaningful in the context, ¿why in StringToVector() the result vector is called
GuessVector?
- seems that HiddenNumberGenerator() is checking repeated elements, ¿why don't simply call to CheckNumbers()? (bonus, ¿can you guess why `Error' is always even?)
- in the condition in line 121 you are checking to see if that's the last iteration of the loop, ¿why isn't simply
outside the loop?
- you have IntToStrig() and then StringToVector(), may do IntToVector() ¿but why so much yo-yo code?