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.
int find_replace(string& stars, string clear, char guess)// Clear =phrase before changed to stars
int times=0, n=0;
while( n <= clear.length() -1)
if (clear[n] == guess )
clear[n]= guess; n++; times ++;
else if (clear[n] != guess )
cout << "WRONG!" << endl;
else if(clear[n] == ' ')
clear[n] = clear[n]; n++;
cout << stars << endl;
I just want to see if anyone can point out the flawed logic in this. I'm pretty sure it's something obvious but I've been looking at it too long too see it!
- You never try to change stars, so consequently it does not change.
- You probably don't want to print WRONG for every letter in the word, only if no matches are found.
- I wish you the best of luck in getting to that third branch.
I looked at it for 5 seconds, then decided the indentation was too confusing to waste more time on it.
SourceForge.net: Indentation - cpwiki