Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream> #include<fstream> #include<string> using namespace std; bool

ID: 3744656 • Letter: #

Question

#include <iostream>

#include<fstream>

#include<string>

using namespace std;

bool checkIfPresent(string);

int main()

{

std::ifstream infile("LetterWord.txt");

string inp = "y";

while (inp != "-1")

{

cout << "Enter a word or -1 to quit: ";

cin >> inp;

if (inp == "-1")

{

break;

}

if (checkIfPresent(inp))

{

cout << "The word was spelled correctly" << endl;

}

else

{

cout << "The word was not spelled correctly" << endl;

}

}

}

bool checkIfPresent(string word)

{

std::ifstream infile("LetterWord.txt");

if (infile.is_open())

{

std::string line;

while (getline(infile, line))

{

if (line == word)

{

return true;

}

}

}

infile.close();

return false;

}

This C++ program It seems the program run incorrectly, please help thank you very much

Explanation / Answer

Program has no error. I checked here.I guess it would be better if you provide the file which is used as dictionary to compare. As, I guess as exact the program is fetching complete line , so the file might have indentation or something.