Feb 14, 2015 at 8:31pm UTC
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 Feb 14, 2015 at 8:32pm UTC