prog4_08.cpp
来自「c++最经典的入门书籍」· C++ 代码 · 共 39 行
CPP
39 行
// Example 4.8 Using the switch statement
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main() {
int choice = 0; // Store selection value here
cout << endl
<< "Your electronic recipe book is at your service." << endl
<< "You can choose from the following delicious dishes: "
<< endl
<< "1 Boiled eggs" << endl
<< "2 Fried eggs" << endl
<< "3 Scrambled eggs" << endl
<< "4 Coddled eggs" << endl
<< endl << "Enter your selection number: ";
cin >> choice;
switch(choice) {
case 1:
cout << endl << "Boil some eggs." << endl;
break;
case 2:
cout << endl << "Fry some eggs." << endl;
break;
case 3:
cout << endl << "Scramble some eggs." << endl;
break;
case 4:
cout << endl << "Coddle some eggs." << endl;
break;
default:
cout << endl << "You entered a wrong number, try raw eggs." << endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?