okay i've got a problem with this code its going to be a apart of a word guessing game, the problem is that my code reads the file i want it too, but when i ttry to guess the letter it will only read the first letter, i know that i have alot of libraries open its a copied code from my main program.
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <iomanip>
#include <cmath>
using namespace std;
vector<string> words; // list of words to get
int main() //main
{
srand(time(0)); //gets the random word
bool notFound = false;
string line;
string soFar;
ifstream infile( "Animals.txt" , ios::in );
if(! infile) {
cout<<"Cannot open input file\n";
}
while(getline(infile,line)){
words.push_back(line);
}
infile.close();
string THE_WORD = words[0];
for(int i=0;i<5; i++){
soFar = string(words[0].size(), '*');
}
cout<<words[0]<<endl;
cout<<soFar<<endl;
int live = 8;
char guess;
do{
cout << "\n\nEnter your guess: ";
cin >> guess;
guess = toupper(guess);
for(int i=0;i<THE_WORD.length(); i++){
if(THE_WORD.at(i)==guess){
soFar.at(i)= THE_WORD.at(i);
cout<<guess<< " was found at "<< i <<endl;
notFound = false;
}else{
notFound=true;
}
}
cout<<soFar<<endl;
if(notFound){
live--;}
cout<<"you have "<<live<<" left\n";
}while((soFar!= THE_WORD) && live>0);
if(soFar== THE_WORD){
cout<<"you won with "<<live<<" left\n";}else{
cout<<"you lost\n";
}
system("pause");
return 0;
}