Ive been having trouble solving this please help, yea its hw but im using this as a last resort as its due in 2 hours.

// Search a dictionary file for the word input by the user.
//
//////////////////////////////////////…

#include<iostream>
#include<string>
#include<fstream>

using namespace std;

int main()
{
string word; // The word entered by the user
string result; // The word read from the file
int counter = 0; // Counts the number of lines read from the file
bool found = false; // If the user's word has been found
ifstream inFile; // The input file


///////////////////////////////////
// Start of your code

//open the dictionary file.

inFile.open("dictionary.txt");


//ask the user to input the word they want to search for.

     cout<<"Enter a word to search in dictionary:";
     cin>>word;


// Use a while loop to loop through the file.
// Use break to stop the loop if the word is found




// If the word is not found display a message.

if ( found )

	cout<<"Word was not found";

// End of your code
///////////////////////////////////


system("pause");
return 0;
}

Two hours, eh? Just out of curiosity, how long have you been working on this assignment?

About 3 hours or so, this is my 3rd week with c++ so take it easy lol.

I see. And when was the assignment first given to you?

Oct. 6, 11:59 PM but spent most of the time reading the textbook. So any chance you could help?

Given that you've had plenty of time to complete this and the code you posted suggests you've done nothing at all, I think it would be more productive if I taught you the importance of time management by watching you get a failing grade on the assignment. Sadly, many people need to be burned before the lesson hits home.

That's not to say that I won't help, provided you ask a smart question and don't expect me to write the program for you.

This is clear example of overly-commented code. If someone ever says "there is never enough commenting" to me, I am going to send them link to this.

Now to your assignment:
This is one of the worst programs I ever saw, and I am "taking it easy lol". You did not write the loop, input from the file or anything like that.
First make an ARRAY of STRINGS. Then use while loop to input from the file. Then use another while loop to search for words.

This is one of the worst programs I ever saw, and I am "taking it easy lol".

The code is just fine, though it's obvious the teacher wrote the majority of it and left comments for students to fill in the blanks. If this is one of the worst programs you've ever seen, I envy you. :D

Yes, I see now. At first I just skimmed through the program (not reading the comments).
But if teacher wrote it, then why would he declare result as only a string, not an array of strings? Usually when reading from file, it reads 1 word at a time and stores each word seperately, right?
And I envy you for seeing the "bad" code. Really educational, and good experience that is needed in programming world :D

Right...Well, I finally figuerd it out, just needed to keep reading the textbook. Thanks for the link gerard4143.

commented: Good job +7
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.