I'm making a wordle program for a class assignment and the basic concept is to load all 5 letter words in the English language from a text file into an array, then pick one randomly to be the correct one, and I have that part correct (probably isn't that efficient but it works for now). I need to verify the user input that the 5 letter word they entered is actually in that array. For example they enter "djghd", which isn't a word that would be in that array. here is the code that I used:
#include <string>
#include <fstream>
#include <ctime>
using namespace std;
bool verifyExists(string word, string verifyArr) {
for (int i = 0; i < 2315; i++)
{
if (word == verifyArr[i])
{
return true;
} else {
return false;
}
}
}
void playGame(string word, string arr) {
string guessWord;
cout << "Ok. I am thinking of a word with 5 letters." << endl;
cout << "What word would you like to guess?" << endl;
getline(cin, guessWord);
verifyExists(guessWord, arr[2315]);
cout << guessWord << endl;
}
int main() {
string word;
int loop = 0;
string wordArray[2315];
ifstream myfile ("proj1_data.txt");
cout << "Welcome to UMBC Wordle" << endl;
if (myfile.is_open())
{
cout << "Your file was imported!" << endl;
cout << "2315 Words imported" << endl;
while (! myfile.eof())
{
getline(myfile, word);
wordArray[loop] = word;
loop++;
}
myfile.close();
}
int max;
max = 2315;
srand(time(0));
string chosenWord = wordArray[rand() % max];
playGame(chosenWord, wordArray[2315]);
return 0;
}
When I try to compile it, it throws a ton of errors (Which might just be the compiler I'm using) and i need to use infinite scroll to get through them all so I cant add them here. They only show up after I added the verifyExists function so I know that's the source of the error I just don't know what is causing it. I'm also not allowed to use pointers so that makes it difficult. Any help is greatly appreciated, thank you.