0
在下面,我希望程序退出,如果「條件」在函數2中小於3,但目前它只是在switch語句後繼續執行代碼。我如何去實現我的目標?如何返回0並終止函數?
#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;
}
'出口(0);'<需要15個字符> – ApproachingDarknessFish 2013-04-07 03:55:58