cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Killing a program using an input rather
Killing a program using an input rather than ctrl+c?
Feb 14, 2015 at 8:35pm UTC
Tig3r125
(4)
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 ();}
}
Feb 14, 2015 at 9:52pm UTC
MiiNiPaa
(8886)
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.