To Whomever Can help Me;
Is it possible to use the Switch structure for characters? For example:
switch(char)
{
case 1:char = 'b'
.
.
.
I'm trying to do it, but having trouble. Is this even possible? Any help would be great! Thanks!
Dave
To Whomever Can help Me;
Is it possible to use the Switch structure for characters? For example:
switch(char)
{
case 1:char = 'b'
.
.
.
I'm trying to do it, but having trouble. Is this even possible? Any help would be great! Thanks!
Dave
It is possible:
try thatCode:char choice; printf("Enter a letter...:"); scanf("%c", choice); switch (choice) { case 'a': { ... } case 'b': { ... } }
Last edited by Lau; 11-18-2002 at 01:14 PM.
Yes, chars and ints can be used in switches. But don't name a variable 'char' it's a keyword y'know? Also, the label cannot be a variable name, see below:
Code:char a = 'a'; char b = 'a'; switch(a){ case b: a = 'x'; break; // <-- illegal. case 't': a = 'z'; break; case 12 : a = 'r'; break; default: a = 'p'; }
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }