hour06_3.cpp
来自「《24学时精通c++》的随书源码的下半部分。欢迎下载学习。」· C++ 代码 · 共 39 行
CPP
39 行
//Listing 6.14
// Demonstrates switch statement
#include <iostream>
int main()
{
unsigned short int number;
int looper;
std::cout << "Enter a number between 1 and 5: ";
std::cin >> number;
switch (number)
{
case 0:
std::cout << "Too small, sorry!";
break;
case 5:
std::cout << "Good job!\n"; // fall through
case 4:
std::cout << "Nice Pick!\n"; // fall through
case 3:
std::cout << "Excellent!\n"; // fall through
case 2:
std::cout << "Masterful!\n"; // fall through
case 1:
std::cout << "Incredible!\n";
for (looper = 1; looper < 5; looper++)
std::cout << "Loop value is " << looper << "\n";
// That's how you do it and, unless I've really goofed up,
// it should compile. Any regular statement should work within
// the switch statement!
break;
default:
std::cout << "Too large!\n";
break;
}
std::cout << "\n\n";
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?