forked from Codecademy/learn-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ufo.cpp
52 lines (32 loc) · 858 Bytes
/
ufo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include "ufo_functions.hpp"
int main() {
greet();
std::string codeword = "codecademy";
std::string answer = "__________";
int misses = 0;
std::vector<char> incorrect;
bool guess = false;
char letter;
while (answer != codeword && misses < 7) {
display_misses(misses);
display_status(incorrect, answer);
std::cout << "\n\nPlease enter your guess: ";
std::cin >> letter;
for (int i = 0; i < codeword.length(); 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;
}
end_game(answer, codeword);
}