I am designing a simple game that takes random word from a file, turns the string into stars and then the user guesses the string character by character, so basically like wheel of fortune!
I have everything else working but I am currently trying to design a function that will take the string of stars(which is passed by reference) and replace it with the guess character if it is right by searching the phrase before it was turning into a string of stars.
Code:
int find_replace(string& stars, string clear, char guess)// Clear =phrase before changed to stars
{
int times=0, n=0;
string guess1;
while( n <= clear.length() -1)
{
if (clear[n] == guess )
{
clear[n]= guess; n++; times ++;
}
else if (clear[n] != guess )
{
cout << "WRONG!" << endl;
n++;
}
else if(clear[n] == ' ')
{
clear[n] = clear[n]; n++;
}
}
cout << stars << endl;
return times;
}