Something wrong about this code

This part of my code does not produce its desired purpose.

1
2
3
4
5
6
7
8
9
10
int a=0,b=0;
cout<<"Please choose the root domain: "<<endl;
		cout<<"1. [1,2] 2. [-2,-1]"<<endl;
		cin>>h;
		if (h==1)
				a=1;b=2;
		if (h==2)
				a=-2;b=-1;
		if (h!=1 && h!=2)
				cout<<"Error!"<<endl;


I was thinking that this program will prompt me a question about the domain and then, when I pick one, the values of my a and b will change throughout the remaining processes.
1
2
3
4
5
6
7
8
if (h==1)
	a=1; // only this is affected by the if statement
        b=2; // this gets called always
if (h==2)
	a=-2;
	b=-1; // same here
if (h!=1 && h!=2)
	cout<<"Error!"<<endl;



surround the code after if statements with curly brackets to make it work.


1
2
3
4
5
6
7
8
9
10
11
12
if (h==1)
{
	a=1;
        b=2;
}
if (h==2)
{
	a=-2;
	b=-1;
}
if (h!=1 && h!=2)
	cout<<"Error!"<<endl; // this can be without cus its just 1 statement 


otherwise its good if h is a number variable.
Last edited on
Thanks!
Topic archived. No new replies allowed.