need help in switch statement

how can i add -1 in switch statement cuz even i put -1 nothing happen

heres the code i've done

int a;
cin >> a;

switch(a)
{
case -1 :
{
return 0;
}
default:
{
cout << "Your number " a << " is greater than 0";
}
}
... i put -1 nothing happen
return 0; will do that.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;

int main()
{
int a;
cin>>a;
switch (a)
{
case -1:
cout<<"-1"<<endl;
break;
default:
cout<<"Default"<<endl;
}
return 0;
}


you forgot the break statement
please give more information on what you are trying to do.
this might help:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

void main(){
int a;
cout<<"Enter a number"<<endl;
cin>>a;
switch(a){
case -1://If you enter (-1) then it will work
cout<<"The case is -1"<<endl;
break;//Used to get out of switch statement

default:

cout << "Your number  "<< a << " is greater than 0";
 
break;
}

system("pause");
}
thanks
You don't normally need another break after the default statement.
Topic archived. No new replies allowed.