I don’t know what’s wrong with this code.
Many bugs can anyone check what is it?
Hey!
Let’s try to problem-solve.
What are the errors? Why do you think they’re happening?
1 Like
Worked on it for 3 days completed it today and I don’t think there should be any errors I went through all the hints. Can you reveal the answer
I think the problem is in the order of your main() function…
Hope this helps.
#include <iostream>
#include "ufo_functions.hpp"
int main() {
// Define variables
std::string codeword = "codecademy";
std::string answer = "__________";
int misses = 0;
std::vector<char> incorrect;
bool guess = false;
char letter;
// Let's say Hello and explain the game
greet();
// Start playing
while (answer != codeword && misses < 7) {
display_misses(misses);
display_status(incorrect, answer);
std::cout << "Please enter your guess: ";
std::cin >> letter;
for (int i = 0; i < codeword.size(); i++) {
if (letter == codeword[i]) {
answer[i] = letter;
guess = true;
}
}
if (guess) {
std::cout << "\nCorrect!\n";
}
else {
std::cout << "\nIncorrect! The tractor beam pulls the person in further.\n";
incorrect.push_back(letter);
misses++;
}
guess = false;
}
// Did you win?
end_game(answer, codeword);
}