Exiting a program using a user input rather than killing it with ctrl+c

How would you kill a program using an input code? i have called the exit function but i don't know what i am doing wrong.

the following is my code:

#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 ();}
}
Last edited on
It won't exit from your program just because you called it "exit", you've got to implement in too. You can also use exit() from cstdlib: http://goo.gl/SxFgEq
Topic archived. No new replies allowed.