Bugfix, 0 correct doesnt end the game

This commit is contained in:
Matti 2024-11-13 22:49:44 +01:00
parent df6e679963
commit f37af51671

View File

@ -40,8 +40,9 @@ std::vector<std::string> generateSecretCode(int digits, int optionsPerDigit) {
return secretCode;
}
std::vector<std::string> getCodeGuessFromConsole(int codeLength) {
std::vector<std::string> getCodeGuessFromConsole(int codeLength, int livesRemaining) {
std::cout << "Have a Guess!" << std::endl;
std::cout << "You have " << livesRemaining << " more Attempts before you will be roasted" << std::endl;
std::vector<std::string> guess;
@ -104,25 +105,25 @@ int countMatches(std::vector<std::string> &v1, std::vector<std::string> &v2) {
}
void Aufg5Main() {
int optionsPerDigit = 4;
int codeLength = 4;
int livesRemaining = 5;
int optionsPerDigit = 99;
int codeLength = 1;
int livesRemaining = 2;
std::cout << optionsPerDigit << " options per Digit" << std::endl;
std::cout << codeLength << " Code Length" << std::endl;
std::cout << livesRemaining << " Lives Remaining" << std::endl;
std::cout << "======================================" << std::endl;
std::vector<std::string> SecretCode = generateSecretCode(codeLength, optionsPerDigit);
std::cout << "I have locked the door with a secret Code, you will never be able to figure it out!!" << std::endl;
// printAllStringsInVector(SecretCode);
int perfectCounter = 1;
while (perfectCounter && livesRemaining) {
std::vector<std::string> guess = getCodeGuessFromConsole(codeLength);
while (livesRemaining) {
std::vector<std::string> guess = getCodeGuessFromConsole(codeLength, livesRemaining);
perfectCounter = countPefectMatches(guess, SecretCode);
int perfectCounter = countPefectMatches(guess, SecretCode);
std::cout << "correct were: " << countMatches(guess, SecretCode) << std::endl;
std::cout << "perfect were: " << perfectCounter << std::endl;
std::cout << "perfect were: " << perfectCounter << std::endl << std::endl;
livesRemaining--;