My partner and I are having a little trouble working around a (what seems to be) minor problem.
In wheel of fortune we have a text file that contains a category and phrase (for example: school jacksonville_state_university)that are on different lines. When we read in the phrase, it includes the underscores. I included underscores because when I just did spaces, it only read in the last word. I want to print a "board" something like what hangman would print (for example for the word school,
cout "------"). If there is more than one word, I would like to cout a space for the underscores. Any help would be great. Also, if there is a different way to do this that would be more efficient, that would be great too. Here is the section of code for that part that I have come up with. I creates a compiler error saying that C++ cannot compare integers and pointers:
Well, I've run into another small problem. Now it prints out the letter in the correct spot, but it will only show one letter at a time. For example, if the word is: dog and the user guesses "d" it will show d--. If the user guesses "g" on the next guess, it will show --g. Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// COUT BLANKS FOR THE PHRASE AND REPLACE DASHES WITH LETTERS
for(int i = 0; i < phrase_length; i++){
char y = phrase[i];
if(y == '_'){
cout << " ";
}
if(y != '_' && player_choice != y && guessed_letters[i] != y){
cout << "-";
}
if(y != '_' && player_choice == y && guessed_letters[i] != y){
cout << player_choice;
}
if(y != '_' && player_choice == y && guessed_letters[i] == y){
cout << guessed_letters[i];
}
}
Instead of using cout a bunch of times, what if you made another char array, of the same size as the phrase, and initalized it with all '-' characters, then, if the user's guess matched any of the original phrase's letters, replace the copy's '-' in that spot with the correct letter? Then you can print out the copy array. Try that and post back.
BOOM! Perfect! Thank you so much! My partner and I were sooo close to doing that, but what we did is left our initializer in the while loop and it initialized every time, so it didn't look like it was updating. that way was so much shorter too. When I finish, I will post all of my code.
Ok here is my code. We only had to write code for one player because of time constraints and I could do more tomorrow, but I am going to bed. I still have to make more than one category, but that isn't the biggest part of it. It works pretty well though, but there could obviously be some improvements made.
So, it's not 100% finished, but it is mostly done aside from a few little tweaks here and there.