I'm currently writing a guess the password game but I'm stuck in the output part. For example if the password is 12345, which it will shown as "*****", then if I guess 13465, it will show 1***5. I have 5 chance to choose it. Here's my codes:
<conio.h> has been deprecated long time ago and you really don’t need it.
One possible basic logic can be:
Create your password as a std::string (ex. by reading the user input by means of std::cin or std::getline()). Let’s call it ‘x’, if you want (I think it’s a confusing name).
Create another std::string of the same length of the previous, but filled with asterisks. Let’s call it ‘to_out’.
--> In a loop:
Ask the user a guess. Record the answer in a third std::string, say ‘attempt’. Verify if the user has input exactly as many characters as there’re in ‘x’.
Compare ‘x’ and ‘attempt’ character by character. For every char which matches, change the corresponding char in ‘to_out’ from asterisk to the correct one.