我已经创建了一个菜单来调用不同的程序。我的第5个程序中也有一个菜单,可以执行不同的功能。
我想知道的是如何允许用户退出程序5并返回原始主菜单。好像我应该知道这个...
这是我的代码示例:
主菜单:
int main() {
while (true)
{
system("cls");
int option = menuOption();
switch (option)
{
case 1: Program1(); break;
case 2: Program2(); break;
case 3: Program3(); break;
case 4: Program4(); break;
case 5: Program5(); break;
default: return 0;
}
system("pause");
}
return 0;
}
程序5菜单:
void Program5() {
int score, selection;
string player;
while (true)
{
system("cls");
cout << "\n\t Menu\n\t==========\n";
cout << "1. Add a player and score\n";
cout << "2. Show top 10 players & scores\n";
cout << "3. Search for a player\n";
cout << "4. Remove a player\n";
cout << "5. Exit to main menu\n";
cout << "\t==========\n";
cout << "Option: \n";
cin >> selection;
cout << endl;
switch (selection)
{
case 1:
//Doesn't matter
case 2:
//Doesn't matter
case 3:
//Doesn't matter
case 4:
//Doesn't matter
case 5:
return;
break;
default: exit(1);
}
system("pause");
}
}
答案 0 :(得分:1)
您应该删除@Html.EditorFor(model => model.EmailAddress,
new { htmlAttributes = new { @class = "form-control width100", @required = "required" } })
语句和system("pause");
语句。您不想退出该程序。
之后,根据您的代码,它应该返回到default: exit(1);
并进行while循环的另一次迭代以询问菜单选项。
答案 1 :(得分:0)
返回后,您将返回主目录。例如,这段代码:
maxfunction = numpy.vectorize(lambda i: max(i,0.5))
print(maxfunction(currentGrid[newIndices]))
给出以下输出:
#include <iostream>
using namespace std;
void Program1(){
}
void Program2(){
}
void Program3(){
}
void Program4(){
}
void Program5(){
int score, selection;
string player;
while (true)
{
system("cls");
cout << "\n\t Menu\n\t==========\n";
cout << "1. Add a player and score\n";
cout << "2. Show top 10 players & scores\n";
cout << "3. Search for a player\n";
cout << "4. Remove a player\n";
cout << "5. Exit to main menu\n";
cout << "\t==========\n";
cout << "Option: \n";
cin >> selection;
cout << endl;
switch (selection)
{
case 1:
//Doesn't matter
case 2:
//Doesn't matter
case 3:
//Doesn't matter
case 4:
//Doesn't matter
case 5:
return;
break;
default: exit(1);
}
system("pause");
}
}
int main(){
while(true){
cout << "In main():\n";
int option;
cin >> option;
switch (option)
{
case 1: Program1(); break;
case 2: Program2(); break;
case 3: Program3(); break;
case 4: Program4(); break;
case 5: Program5(); break;
default: return 0;
}
}
}