0

In the following, I wish for the program to exit if "condition" is less than 3 in function2, but at the moment, it just continues code execution after the switch statement. How do I go about achieving my goal?

#include <iostream>

using namespace std;

int main ()
{
    string answer;
    int selection;

    do
    {
        cin >> selection;

        switch(selection)
        {
            case 1:
            function1();
            break;

            case 2:
            function2();
            break;

            default:
            break;
        }

    cout << "Anything else?" << endl;
    cin >> answer;

    }while(!(answer == "no"));

    return 0;
}

void function1()
{   
    //do stuff
}

int function2()
{
    int condition;

    cin >> conditon;

    if(condition < 3)
    {
        cout << "That's an error." << endl;
        return 0;
    }
    return 0;
}
Iswanto San
  • 18,263
  • 13
  • 58
  • 79
Switchkick
  • 2,716
  • 6
  • 21
  • 28

1 Answers1

1

include <stdlib.h> in your header and put exit(0) instead of return 0, that works for me :)

oentoro
  • 740
  • 1
  • 11
  • 32