okay, I reformatted your code and got rid of the syntax errors for you. and if you ever mix spaces and tabs again I'll have to hire an assassin.
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string name;
string question;
string subject;
string file;
string response;
bool keepgoing=false;
do
{
cout<<'\n'<<name<<" says: ";
getline (cin, question);
if ( question == "do you know?" )
{
cout<<"What do you want to know?\n\n"<<name<<" says: ";
getline (cin, subject);
file = subject + ".txt";
ifstream c_file(file.c_str());
if (!c_file.is_open())
{
cout<<endl<<"Sorry I do not know what "
<<subject<<" is.\n\n"
<<"Please enter a definition of "
<<subject<<".\n\n"
<<name<<" says: ";
getline (cin, response);
ofstream d_file ( file.c_str() );
d_file<<response<<endl;
d_file.close();
cout<<"\nThank you! I now know what "<<
subject<<" is.\n\nHow about another "
<<"question!"<<endl;
keepgoing = 1;
}
else
{
c_file>> response;
cout<<response
<<"\n\nThere you go! Thats all I know "
<<"about "<<subject<<"!\n\nSo let's "
<<"get on to the next question..."
<<endl;
keepgoing = true;
}
}
else if ( question == "who are you?" )
{
cout<<"I am Smarterthanchild, the world's only "
<<"completely\nuseless talking robot and "
<<"hopefully there are many\nin development\n\n"
<<"So that's my life story, ask a question now."
<<endl;
keepgoing = true;
}
else
{
cout<<"My grasp of English is so bad that I can't\n"
<<"understand that!\n\nAsk me another question "
<<"and we'll see if I can understand!"<<endl;
keepgoing = true;
}
} while ( keepgoing );
return 0;
}
edit: some of the changes you should notice right away (I don't even remember all the changes I made)
- better formatting (all tabs)
- slightly more efficient code (no need to call endl for every newline)
- changed keepgoing to a boolean variable
edit2: it's dinner time, so I can't work on it right now, but the first thing that catches my attention is that you're opening the file for writing without any mode flags. Probably not your main problem, but definately not a good idea.