小编See*_*ist的帖子

为什么我的if-else语句会流向第三个呢?

我试图了解这种控制语法是如何工作的.

注意:这是我的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包括在内?你能给我举个例子吗?

c++ loops if-statement

1
推荐指数
1
解决办法
53
查看次数

标签 统计

c++ ×1

if-statement ×1

loops ×1