I want to know if you can end a program from within a void function. I know that with using void()
, you can't just do return 0
, so what is there that would allow me to end my program early?
Here is some code to help you understand my situation:
void checkInput(int a) {
if (a is negative) {
cout << "Your number can't be negative" << endl;
// exit program
}
else {
// move on to calculate square root function
}
}
What I am trying to do here is simulate a problem where a function checkInput()
will check and see if a number is negative before it goes onto the next function, which actually performs the square root of the number, so I want to make sure it's not negative. If it is negative, I want to exit out of the program. This is just an example program.