The Keyword Default
To specify the code to execute if there is no case match, you can use default
keyword in switch statement. For example, the coffee machine has a list of types of coffee by its number (from 1 to 3). If you want to choose one, just type its number. But there is a huge amount of numbers that users can type by mistake. Here we can use the default
keyword:
99123456789101112131415161718// Declare and assign the variableint number;cin >> number;// Choose coffeeswitch (number) {case 1:cout << "Espresso";break;case 2:cout << "Latte";break;case 3:cout << "Cappuccino";break;default:cout << "Your number isn't valid. Please, try again.";}
The default
statement executes the code when the non of statements are true.
The
default
statement must be at the end of the switch.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 3. Розділ 9
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат