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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
void guessWord(string& guess, string& guessed, string list[], int& word, int& counter)
{
cout << "Your code is " << guess.length() << " characters long" << endl;
cout << "Please make your guess or enter # to stop: ";
cin >> guessed;
while(guessed == "#" || guessed.length() != guess.length())
{
if(guessed == "#")
{
fail(list, word, guess, guessed, counter);
}
else
{
cout << "The guess must be the same number of characters as your code word." << endl;
cin.clear();
cin.ignore(1000, '\n');
}
cout << "Your code is " << guess.length() << " characters long" << endl;
cout << "Please make your guess or enter # to stop: ";
cin >> guessed;
}
if(guessed != guess)
{
wrong(guess, guessed, counter);
}
while(guessed == guess)
{
right(list, word, guess, guessed, counter);
}
}
void wrong(string& guess, string& guessed, int& counter)
{
counter = counter + 1;
string check(guess.length(), '_');
int pos = 0;
int val = 0;
cout << "You have guessed " << counter << " times" << endl;
cout << "You entered " << guessed << endl;
cout << "That is not the code word." << endl;
for(int i = 0; i < guess.length(); i++)
{
for(int j = 0; j < guess.length(); j++)
{
if(guessed[j] == guess[j] && i == j)
{
check[j] = 'x';
pos++;
}
else if(guessed[j] == guess[j] && i != j)
{
check[i] = 'o';
val++;
}
else
{
continue;
}
}
}
cout << "You have " << pos << " characters in the right position, and you have " << val << " correct characters in the wrong position." << endl;
cout << "Comparison: ";
for(int i = 0; i < guess.length(); i++)
{
cout << check[i];
}
cout << endl;
}
|