我试图了解这种控制语法是如何工作的.
注意:这是我的int.main功能的一部分:
while(cin >> Options){
if(Options == 1){ //If I enter '1' here it will output: "aHi.Else."
cout << "a";
}else{
cout << "hi";
}
if(Options == 2){ //If I enter '2' here it will output: "hiaElse."
cout << "a";
}else{
cout <<"Hi.";
}
if(Options == 3){ //If I enter '3' here it will output: "hiHi.a"
cout << "a";
}else{
cout << "Else." << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
它为什么会滴到else's什么东西?语法有什么问题?我糊涂了?我如何使用多个if语句而不else's包括在内?你能给我举个例子吗?