From f5ce0edf4c87a7d67ec2413aa640e5d38b0b4a91 Mon Sep 17 00:00:00 2001 From: Matti Date: Wed, 13 Nov 2024 21:29:55 +0100 Subject: [PATCH] Implement Counting perfect Matches --- Aufg5/Mastermind.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Aufg5/Mastermind.cpp b/Aufg5/Mastermind.cpp index d51f7a6..2124f70 100644 --- a/Aufg5/Mastermind.cpp +++ b/Aufg5/Mastermind.cpp @@ -59,6 +59,25 @@ std::vector getCodeGuessFromConsole() { return guess; } +int countPefectMatches(std::vector &v1, std::vector &v2) { + int shorterSize; + + if (v1.size() < v2.size()) { + shorterSize = v1.size(); + } else { + shorterSize = v2.size(); + } + + int count = 0; + for (int i = 0; i < shorterSize; i++) { + if (v1[i] == v2[i]) { + count++; + } + } + + return count; +} + @@ -73,5 +92,6 @@ void Aufg5Main() { printAllStringsInVector(SecretCode); std::vector guess = getCodeGuessFromConsole(); + std::cout << "correct were: " << countPefectMatches(guess, SecretCode) << std::endl; }