switch case out

Hi
I run the following program and excepting answer "third" but I did get.
Could anyone point me reason.


using namespace std;

int main()
{
int a=10;
switch(a)
{
case '1':
cout<<" one"<<endl;
break;
case '2':
cout<<"second "<<endl;
break;
defa1ut:
cout<<"third"<<endl;
}
return 0;
}
Last edited on
It's default (with an L), and also, '1' represents a character, while 1 represents the integer 1.
Aw, C++ has no built-in support for 1337-speek?

1
2
3
4
#define d3f@u17 default
#define sw17ch switch
#define c@s3 case
//Don't you dare do this. 


Aside from that, filipe +1 on all counts. default is spelled with a lowercase 'L' and '1' represents the number 49 (the decimal ASCII code for the character '1') while 1 represents itself.

Also... did you #include <iostream> ? Some compilers and IDEs include it by default, but it's a good habit to include it regardless. If you did and just didn't add that line... well, nevermind!

-Albatross
Last edited on
hi

try replacing it with this :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

using namespace std;

int main()
{
int a=10;
switch(a)
{
case '1':
cout<<" one"<<endl;
break;
case '2':
cout<<"second "<<endl;
break;
default:
cout<<"third"<<endl;
}
return 0;
}


Your code will always output : third

since int = 10
and default = cout << "third" << endl;

Your problem was lurking here defa1ut

mistype? :P
Thx for reply

Ya correct I think this was issue. I got undertsanding why compiler did not give me any error

during compilation
Last edited on
Topic archived. No new replies allowed.