Code:
#include <string>
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
string question = "";
string response = "";
string subject = "";
string file = "";
string name = "";
string help = "";
int keepgoing = 0;
ifstream a_file ( "name.txt" );
if ( !a_file.is_open() ) {
cout<<"Hello. I have never met you before."<<endl;
cout<<endl;
cout<<"What is your name?"<<endl;
cout<<endl;
cout<<"Type your name: ";
getline (cin, name);
cout<<endl;
ofstream b_file ( "name.txt" );
b_file<<name;
b_file.close();
cout<<"As you are new, would you like to find out how I work?"<<endl;
cout<<name<<"'s says: ";
getline (cin, help);
if ( help == "no") {
help == "yes";
}
else {
help == "no";
}
}
else {
cout<<"Hello "<<name<<". Nice to see you again!"<<endl;
cout<<endl;
cout<<"Do you still remember how I work?"<<endl;
cout<<endl;
cout<<name<<"'s says: ";
getline (cin, help);
if ( help == "yes" ) {
help == "yes";
}
else {
help == "no";
}
}
if ( help == "no" ) {
system("CLS");
cout<<"I am the greatest revelation in computing technology since"<<endl;
cout<<"the the invention of Microsoft DOS. You can ask me different"<<endl;
cout<<"questions. However, as I am in the early stages of deveolment"<<endl;
cout<<"I can only understand do you know and who are you questions."<<endl;
cout<<endl;
cout<<"For an answer to a do you know question type in 'do you know?'"<<endl;
cout<<"I will reply and then you should type in the subject that you"<<endl;
cout<<"would like for me to tell you about. If I do not know then"<<endl;
cout<<"you can tell me what it is so I will know in the future."<<endl;
cout<<endl;
cout<<"The other question you can ask me is who I am, simply type"<<endl;
cout<<"'who are you' and I will tell you."<<endl;
cout<<endl;
cout<<"And remember, always type in lower case!"<<endl;
cout<<endl;
cout<<"Press enter when you are done.";
cin.get();
endl;
system("CLS");
cout<<"Now that you're ready to talk to me, what do you want to ask?"<<endl;
}
else {
cout<<"So, what do you want to talk about?"<<endl;
}
do {
cout<<endl;
cout<<name<<"'s says: ";
getline (cin, question);
cout<<endl;
if ( question == "do you know?" ) {
cout<<"What do you want to know?"<<endl;
cout<<endl;
cout<<name<<"'s says: ";
getline (cin, subject);
endl;
file = subject + ".txt";
ifstream c_file ( file.c_str() );
if (!c_file.is_open()) {
cout<<"Sorry I do not know what "<<subject<<" is."<<endl;
cout<<endl;
cout<<"Please enter a definition of "<<subject<<"."<<endl;
cout<<endl;
cout<<name<<"'s says: ";
getline (cin, response);
endl;
ofstream d_file ( file.c_str() );
d_file<<subject;
d_file.close();
cout<<endl;
cout<<"Thank you! I now know what "<<subject<<" is."<<endl;
cout<<endl;
cout<<"How about another question!"<<endl;
keepgoing = 1;
}
else {
c_file>>response;
cout<<response<<endl;
cout<<endl;
cout<<"There you go! Thats all I know about "<<subject<<"!"<<endl;
cout<<endl;
cout<<"So let's get on to the next question..."<<endl;
keepgoing = 1;
}
else if ( question == "who are you?" ) {
cout<<"I am Smarterthanchild, the world's only completely"<<endl;
cout<<"useless talking robot and hopefully there are many"<<endl;
cout<<"in development"<<endl;
cout<<endl;
cout<<"So that's my life story, ask a question now."<<endl;
keepgoing = 1;
}
else {
cout<<"My grasp of English is so bad that I can't understand that!"<<endl;
cout<<endl;
cout<<"Ask me another question and we'll see if I can understand!"<<endl;
keepgoing = 1;
}
} while ( keepgoing = 1 );
return 0;
}
It has a problem in the underlined line...parse error...any help?