3.4 switch ... case
另一種「多分支」選擇結構
當你遇到像這樣的多分支選擇結構時,可以用 if...else if...else來解決。

例如:一個像這樣的選單功能
#include <iostream>
using namespace std;
int main()
{
cout << "(1) 提款" << endl;
cout << "(2) 存款" << endl;
cout << "(3) 查詢帳上餘額" << endl;
cout << "(0) 結束" << endl;
cout << "請選擇服務項目(0-3):";
int i;
cin >> i;
if(i==1) {
cout << "進行提款作業中..." << endl;
cout << "提款作業完成!" << endl;
}
else if(i==2) {
cout << "進行存款作業中..." << endl;
cout << "存款作業完成!" << endl;
}
else if(i==3) {
cout << "進行查詢作業中..." << endl;
cout << "查詢作業完成!" << endl;
}
else if(i==0) {
cout << "結束服務" << endl;
}
else {
cout << "無此項目" << endl;
}
return 0;
}