I'm working on a program to hide letters for a guessing game. The puzzle is read from a file to select a random puzzle. The puzzle can have multiple words and punctuation. I made it so that the puzzle appears on the screen, but the puzzle is supposed to show up as dashes so that you can fill in the puzzle yourself. However, only the letters should appear as dashes. The spaces and punctuation should appear normally. I don't know what I did wrong when I tried to make the puzzle into dashes, but it still appears as the word. Can anyone help? Here is the code that I wrote.
ifstream inputFile("input.txt"); //by putting this outside all of the functions, you can use this in all of the functions
//just don't create (define) a new variable with this name.
string getPuzzleFromFile(){ //get the puzzle from the file.
string createPuzzle(string puzzle){ //create the puzzle to be guessed.
int count;
count = 0;
while (count = 0, count < puzzle.length(), count++){
isValidLetter(letter);
char letter=puzzle[count];
void intro(){
cout<<"Welcome to the Puzzle Game. Guess letters to solve the puzzle. "<<endl;
cout<<"Here's your puzzle:"<<endl;
}
void display(string puzzle2)
{
You're trying to solve everything with global variables which is bad.
In isValidLetter() you use a local variable answer which hides the global variable answer. That means when you call isValidLetter() the global answer is not changed and since you don't use the result of isValidLetter()answer (the global one) remains unchanged.
You see that with gobal variables things get easily confusing. Try do this without global variables. Pass them as parameter instead and use the returned variables