---
# System prepended metadata

title: 第三周 選擇敘述 switch...case

---

# 第三周 選擇敘述 switch...case
## switch...case 又稱為多重選擇判斷敘述
與 **適用於某一個範圍的** if...else 的差別在於 **switch...case 適用於不連續的單點值**
## 例題
```cpp=
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string str;
	int index;

	cout << "輸入郵局代號：";
	cin >> str;
	index = stoi(str);

	switch (index)
	{
		case 2825:
			str = "平溪郵局";
			break;

		case 11323:
			str = "金山郵局";
			break;

		case 11354:
			str = "瑞芳九份郵局";
			break;

		case 311555:
			str = "烏來郵局";
			break;

		default:
			str = "輸入錯誤";
			break;
	}

	cout << str << endl;
	system("pause");
}


```