cout << "Please enter a guess: ";
char guess;
cin >> guess;
while(!isalpha(guess))
{
cout<<"You did not enter a letter\n";
cout << "Please enter a guess: ";
cin >> guess;
}
guess = toupper(guess);
while(already_guessed_list.find(guess) != -1)
{
cout << "You already guessed " << guess << endl;
cout << "Please enter a guess: ";
cin >> guess;
while(!isalpha(guess))
{
cout<<"You did not enter a letter\n";
cout << "Please enter a guess: ";
cin >> guess;
}
guess = toupper(guess);
}
return guess;
}
int countOccurences(char guess, const string& secret_word)
{
int n_occurences = 0;
int guess_pos = secret_word.find(guess);
while(guess_pos != -1)
{
n_occurences++;
guess_pos = secret_word.find(guess, guess_pos + 1);
}
return n_occurences;
}
void updateMask(char guess, const string& secret_word, string& mask)
{
int guess_pos = secret_word.find(guess);
while(guess_pos != -1)
{
mask[guess_pos] = guess;
guess_pos = secret_word.find(guess, guess_pos + 1);
}
}
//string functions
string toupper(const string& original)
{
string edited = empty_string;
int length = original.length();
for(int index = 0; index < length; index = index + 1)
{
char symbol = original[index];
if(islower(symbol))
symbol = toupper(symbol);
edited = edited + symbol;
}
return edited;
}
string trim(const string& original)
{
string trimmed = empty_string;
int left = 0;
int right = original.length() - 1;
while(left <= right && isspace(original[left]))
left = left + 1;
while(left <= right && isspace(original[right]))
right = right - 1;
if(left <= right)
trimmed = original.substr(left, right - left + 1);
return trimmed;
}
//random functions
void init()
{
srand(unsigned(time(NULL)));
}
void init(unsigned seed)
{
srand(seed);
}
int nextInt()
{
return rand();
}
int nextInt(int upper_bound)
{
assert(upper_bound > 0);
return nextInt() % upper_bound;
}
int nextInt(int lower_bound, int upper_bound)
{
if(lower_bound > upper_bound)
{
int t = lower_bound;
lower_bound = upper_bound;
upper_bound = t;
}
int range = upper_bound - lower_bound + 1;
int next_int = nextInt(range) + lower_bound;
return next_int;
}