Not sure the correct way to enter my code but here it goes.
Learn C++ | Codecademy
is my link to the code.
I must be too close to the problem but I cannot see what is wrong and it is probably something simple.
Thanks for any help
UFO.cpp
#include
#include “ufo_functions.hpp”
using namespace std;
int misses = 0;
string codeword = “codecademy”;
string answer = “__________”;
int main() {
char letter;
greet();
bool guess = false;
vector incorrect;
while (answer != codeword && misses < 7) {
display_misses(misses);
cout << “incorrect guesses:” << misses << “\n”;
display_status(incorrect, answer);
cout << “Please Enter your guess”;
cin >> letter;
cout << "Your guess = " << letter;
for (int i; i <= codeword.length(); i++) {
if (codeword[i] == letter) {
answer[i] = letter;
cout << "Your guess = " << letter << "answer[i] = " << answer[i];
guess = true;
}
cout << "Your guess = " << letter << "answer[i] = " << answer[i];
if (guess) {
std::cout << "\nCorrect! You're closer to cracking the codeword.\n";
} else {
std::cout << "\nIncorrect! The tractor beam pulls the person in further.\n";
incorrect.push_back(letter);
misses++;
}
}
// misses++;
}
end_game(codeword, answer);
}
ufo_functions.hpp
#include
void display_misses(int misses);
void end_game(std::string codeword, std::string answer);
void greet();
void display_status(std::vector incorrect, std::string answer);
ufo_functions.cpp
#include
#include
using namespace std;
// Define functions
void greet() {
std::cout << “======================\n”;
std::cout << " UFO: The Game\n";
std::cout << “======================\n”;
std::cout << “Instructions: save your friend from alien abduction\n”;
std::cout << “by guessing the letters in the codeword\n”;
}
void end_game(string code, string answer) {
if (answer == code) {
cout << "Hooray! You saved the player\n";
} else {
cout << "Oh no! the UFO just flew away\n";
}
}
void display_status(vector incorrect, string answer) {
std::cout << “\nIncorrect Guesses:\n”;
for (int i = 0; i < incorrect.size(); i++) {
std::cout << incorrect[i] << ' ';
}
cout << “\nCodeword:\n” ;
for (int i; i <= answer.length(); i++) {
cout << answer[i] << ' ';
}
}
void display_misses(int misses) {
cout << "number of misses = " << misses << “\n”;
}