Ok so in my code im trying to beable to let the user enter the name of a list in main then pass the string to word_list function but my program just keeps saying file failed to open. If you spot any other problems please help me with them ive been working on this program for 4 days and im so frustrated.
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <vector>
using namespace std;
string word_list(string RW, string GL)
{
string store_word;
srand(time(0));
ifstream fileIn;
fileIn.open(GL.c_str());
if(fileIn.fail())
{
cout << "File failed to open" << endl;
}
vector<string> words;
while(!fileIn.eof())
{
if(words.size() == words.capacity())
{
words.reserve(words.size() * 3);
}
fileIn >> store_word;
words.push_back(store_word);
}
RW = words[rand() % words.size()];
return RW;
}
int main()
{
srand(time(0));
string original_word;
string shuffled_word;
string random_word;
string choose_list;
string HWLF = word_list(random_word, choose_list);
string guess;
int select;
bool game_loop = true;
cout << "CRYPTO GUESS\n" << endl;
cout << "Do you want to enter words yourself or have the computer give you words?" << endl;
cout << "1) Enter words myself - Not working" << endl;
cout << "2) Have the computer give me words" << endl;
cin >> select;
cin.ignore(50, '\n');
cout << "Select list" << endl;
getline(cin, choose_list);
if(select == 2)
{
while(game_loop != false)
{
shuffled_word = HWLF;
random_shuffle(shuffled_word.begin(), shuffled_word.end());
cout << shuffled_word << endl;
cout << "\n";
while(guess != HWLF)
{
cout << "Your guess: ";
cin >> guess;
if(guess == HWLF)
{
cout << "Is correct!\n" << endl;
break;
}
else if(guess == "Quit" || guess == "quit")
{
cout << "Goodbye thanks for playing" << endl;
return 0;
}
else
{
cout << "Is wrong! Try again\n" << endl;
}
}
}
}
}