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

In C++ Determine if a word entered by the user is spelled correctly. A word is c

ID: 3574783 • Letter: I

Question

In C++ Determine if a word entered by the user is spelled correctly. A word is considered correct if it's found in dict.txt (see required output to get file).

intrest ENTER anchor ENTER fake ENTER hax ENTE ENTER what ENTER 36 ENTE exit Enter word to spellcheck (or exit to end Mn intrest is not spelled correctly. An Enter word to spellcheck (or exit to end)An anchor is spelled correctly. An Enter word to spellcheck (or exit to end Mn fake is spelled correctly. An Enter word to spellcheck (or exit to end) In hax is not spelled correctly. In Enter word to spellcheck (or exit to end Mn wut is not spelled correctly. Nn Enter word to spellcheck (or exit to end) In what is spelled correctly. An Enter word to spellcheck (or exit to end Mn 36 is not spelled correctly. An Enter word to spellcheck (or exit to end) In Ending program. In dict txt

Explanation / Answer

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

int main()
{
   ifstream myf("dict.txt");
   string s,lt[1000];
   int len=0;
   while(myf>>s)
   {
       lt[len]=s;
       len++;
   }
   while(true)
   {
       cout<<"Enter word to spell check(or exit to end):";
       cin>>s;
       if(s.compare("exit")==0)
       {
           cout<<"Ending program..."<<endl;
           break;
       }
       int hat=0;
       for(int i=0;i<len;i++)
       {
           if(s.compare(lt[i])==0)
           {
               hat=1;
               break;
           }
       }
       if(hat==1)
       {
           cout<<s<<" is spelled correctly ";
       }
       else
       {
           cout<<s<<" is not spelled correctly ";
       }
   }
   return 0;
}