在下文中,我希望程序在function2中“条件”小于3时退出,但此时它只是在switch语句之后继续执行代码。我该如何实现我的目标?
#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;
}