Good evening to all seniors here. How to stop the program when user enter 0? I wish to do it by my own. I hope seniors here can give me rough idea on this. Its basically my assignment on implementing tree (BST) and i wish to complete by myself. In case i encountered a problem, i might post my codes here for senior's review. Thanks in advance.
First, your program must determine that the user entered 0. Then, you either return 0; if you are inside int main, or you may call std::exit(0); from anywhere. http://www.cplusplus.com/reference/cstdlib/exit/
int value;
while ((cin << value && value != 0) {
// do something with value;
}
The loop will run until (1) cin<< value is false, which means that the user entered a bad value, or you hit end of file etc, or (2) the value that gets read is zero.
Note that this relies on the fact that && is guaranteed to evaluate its left operand (cin << value) first.