?? list0717.cpp
字號:
//Listing 7.17
//Using a forever loop to manage user interaction
#include <iostream>
// prototypes
int menu();
void DoTaskOne();
void DoTaskMany(int);
using namespace std;
int main()
{
bool exit = false;
for (;;)
{
int choice = menu();
switch(choice)
{
case (1):
DoTaskOne();
break;
case (2):
DoTaskMany(2);
break;
case (3):
DoTaskMany(3);
break;
case (4):
continue; // redundant!
break;
case (5):
exit=true;
break;
default:
cout << "Please select again! " << endl;
break;
} // end switch
if (exit == true)
break;
} // end forever
return 0;
} // end main()
int menu()
{
int choice;
cout << " **** Menu **** " << endl << endl;
cout << "(1) Choice one. " << endl;
cout << "(2) Choice two. " << endl;
cout << "(3) Choice three. " << endl;
cout << "(4) Redisplay menu. " << endl;
cout << "(5) Quit. " << endl << endl;
cout << ": ";
cin >> choice;
return choice;
}
void DoTaskOne()
{
cout << "Task One! " << endl;
}
void DoTaskMany(int which)
{
if (which == 2)
cout << "Task Two! " << endl;
else
cout << "Task Three! " << endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -