Would someone check this? This part of my code does not produce its desired purpose.
[code]
int a=0,b=0;
cout<<"Please choose the root domain: "<
Enclose your if statement code blocks with curly braces (except for the last one since you only have one line of code in it) Otherwise, 'b = 2' and 'b = -1' will be executed even if h is not 1 or 2.
so your code can look like this: int a = 0, b = 0, h; 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;
int a=0, b=0,h; cout<<"\nplease the root domain :"<<endl; cout<<"\n1 . [1,2] 2.[-2,-1]"<<endl; if (h==1) { cout<<"\n\na=1"; <<"\n\nb=2"; } if(h==2) { cout<<"\n\na=-2"; <<"\n\n b=-1"; } if(h!=1 && h!=2) { cout<<"Error"<<endl; }
if you want the message to be prompet rapidly u can use sentinel control statement(while loop)
Join our real-time social learning platform and learn together with your friends!