El “switch” tiene diferentes usos, entre estos están condicional, variables tipo enteros y de caracter
//no agarra decimales!!
Las podemos usar para cambiar entre tipos de variables de manera sencill, y definiendo los valores de cada una!
Es como tener un codigo(no de programación), o definir una variable(no es una explicación precisa)
La syntaxis la saque del link al final:
Syntax
attr(optional) switch ( condition ) statement |
|||||||||
attr(C++11) | – | any number of attributes |
condition | – | any expression of integral or enumeration type, or of a class type contextually implicitly convertible to an integral or enumeration type, or a declaration of a single non-array variable of such type with a brace-or-equals initializer. |
statement | – | any statement (typically a compound statement). case: and default: labels are permitted in statement and break; statement has special meaning. |
attr(optional) case constant_expression : statement |
(1) | ||||||||
attr(optional) default : statement |
(2) | ||||||||
constant_expression | – | a constant expression of the same type as the type of condition after conversions and integral promotions |
De esta manera se puede lograr que funcione un switch.
un ejemplo puede ser el siguiente:
Si no te quedo claro, puedes visitar estas páginas:
http://en.cppreference.com/w/cpp/language/switch
El link al codigo en la imágen es el siguiente:https://github.com/JuanPabloGonzalezHuezzo/Mastery17/tree/master
#TC1017 #Mastery17 by Juan Pablo Gonzalez Huezzo is licensed under a Creative Commons Attribution 4.0 International License.