Killing a program using an input rather than ctrl+c?

I have a program that i am trying to terminate using a input of "quit" i have called the exit () function in my program but i don't understand why its not working. Any help would be appreciated. thanks.



#include <iostream>
using namespace std;

void hello () {
cout << "< Hello, world!" << endl;
cout << "" << endl;
}
void reverse () {
char tmp;
string s;
cout << "> ";
cin >> s;
cout << "< ";
int i, n = s.size ();
for (i = 0; i < n/2; i++) {
tmp = s[i];
s[i] = s[n-i-1];
s[n-i-1] = tmp;
}
cout << s << endl;
cout << "" << endl;
}
void exit() {
cout << "< Goodbye!" << endl;
}

int main () {
string a;
cout << "> ";
cin >> a;

if (a == "hello") {hello(); main ();}
else if (a == "quit") {exit (); main ();}
else if (a == "reverse") {reverse (); main ();}
}
Please, do not double post. It clutters forums and spreads attempts to help you. Another thread: http://www.cplusplus.com/forum/beginner/156719/
Topic archived. No new replies allowed.