C/C++ UFO Project Refactoring

Hello,

I completed the C/C++ UFO Project and my source code compiles and executes. I am however not happy with my source code. There is source code in the main function method procedure that I would like to refactor. Here are hyperlinks to the C/C++ UFO Project and to GitHub with my C/C++ UFO Project Source Code.

C/C++ UFO Project Refactoring

My C/C++ UFO Project Source Code

I tried to refactor the following conditional statement in the main function method procedure:

if (letter == codeword[i]) { answer[i] = letter; guess = true; }

In the file ufo.cpp programs main function I simply replace that conditional statement with a function method procedure call.

letter_check(letter, codeword);

In the file ufo_functions.hpp program I declare:

void letter_check(char letter, string codeword);

In the file ufo_functions.cpp program I define:

void letter_check(char letter, string codeword) { if (letter == codeword[i]) { answer[i] = letter; guess = true; } }

I also try to do this for the second conditional statement in the file ufo.cpp program main function method procedure:

if (guess) { cout << "Correct!" << endl; } else { cout << "Incorrect! The tractor beam pulls the person in further." << endl; incorrect.push_back(letter); misses++; }

when i compile and execute the machine source code I get the following:

ufo_functions.cpp: In function ‘void letter_check(char, std::__cxx11::string)’: ufo_functions.cpp:30:26: error: ‘i’ was not declared in this scope if (letter == codeword[i]) ^ ufo_functions.cpp:32:5: error: ‘answer’ was not declared in this scope answer[i] = letter; ^~~~~~ ufo_functions.cpp:33:5: error: ‘guess’ was not declared in this scope guess = true;

Please advise me