Hello sankarl,
Some hints to get you started:
PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
I found the second link to be the most help.
std::vector<char> v1{ 's', 'l', 'e', 'e', 'p' };
does the same as what you have, but will eliminate ten lines of code because you can do the same for "v2" by replacing the letters with *s.
These two lines
1 2
|
//const int size = 5;
//char answer[size];
|
The first line I would write as
constexpr int MAXSIZE{ 5 };
, you could also just use "const" if needed, and put it at the top of "main" where it is easy to find and change when needed. The capital letters help to remind you that it is defined as a constant.
Line 2 would then be
char answer[MAXSIZE];
.
In the for loop the "cout" statement will always print "guesses" as 10 because "guesses" never changes. Consider the for loop as:
for (int i = 0; i < 10; i++, guesses--)
In function "checkGuess(vector <char> vector)" you have a good start until you reach
vector.push_back(guess);
. All this does is add to the end of the vector. What you need to do is check "v1" to find which element of the vector matches the user guess and then change that same position in "v2" replacing the * with the letter guessed.
If you pass the vector by reference there will be no need to return the vector back to "main". Actually back in main you do not even receive the returned value.
For someone new to coding I do not see this as a mess, but more as uninformed, inexperienced or lack of good teaching. Stick around here for awhile and read as much as you can and you will pick on some good coding and good habits.
Now having looked at your code I see no need for an array, the two line you have commented out, because the vectors are a better choice and you can work with the same as you would an array. So unless it is required I would forget about the array. If it is required a little more information on the way it would be used would help.
I will load your code up and see if I find anything else that I may have missed just looking at the code.
Hope that helps,
Andy