1 //31-switch statement. CPP: Defines the entry point of the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6#include <climits>7#include <array>8#include <math.h>9#include <string>Ten using namespacestd; One A enumHerotype// - { -Tank,//0 theMagic,//1 -Adc//2 -Assist//3 - }; + - intMain () + { A //SWITHC Statement Structure at //switch (integer-expression)//an integer expression - //{ - //Case Lavel1: - //statement1; - //Beak; - //Case Lavel2: in //statement1; - //Beak; to //Default: + //Break ; - //} the *Herotype type =Tank; $ Switch(type)Panax Notoginseng { - CaseTank: thecout <<"Using tank skills"<<Endl; +cout <<"using tank models"<<Endl; A Break; the CaseMagic: +cout <<"Using mage skills"<<Endl; -cout <<"using the wizard Model"<<Endl; $ Break; $ CaseADC: -cout <<"Use shooter Skills"<<Endl; -cout <<"using the shooter model"<<Endl; the Break; - CaseAssist:Wuyicout <<"Using assistive Skills"<<Endl; thecout <<"using the secondary model"<<Endl; - Break; Wu default: -cout <<"no corresponding hero type found"<<Endl; About Break; $ } - - //Any switch statement can be replaced by a if...else statement. See the situation used. - A intVIP =4; + Switch(VIP) the { - Case 0: $cout <<"no presents ."<<Endl; the Break; the Case 1: thecout <<"Complimentary 10 Diamonds"<<Endl; the Break; - Case 2: incout <<"Complimentary 30 Diamonds"<<Endl; the Break; the Case 3: Aboutcout <<"Complimentary 50 Diamonds"<<Endl; the Break; the Case 4: thecout <<"Complimentary 100 Diamonds"<<Endl; + Break; - default: the Break;Bayi } the intT; theCIN >>T; - return 0; -}
C + + Programming basics a 31-switch statement