为什么在if语句满足后仍然打印else语句?

0 c++ if-statement

对不起,我是stackoverflow的新手,但我在编码时遇到了问题.我创建了这个简单的程序,但我注意到它在使用if语句完成后仍然打印了else语句.代码是用c ++编写的,非常感谢您的帮助.

# include <iostream>
using namespace std;

int main()
{
    char check;
    bool done = false;
    while(not done)
    {
        cout<<"Please enter one of the options provided below."<<endl;
        cout<<"D = distance S = second F = first"<<endl;
        cin>>check;
        if(check == 'D')
        {
            cout<<"You pressed D"<<endl;
        }
        if(check == 'S')
        {
            cout<<"You pressed S"<<endl;
        }
        if(check == 'F')
        {
            cout<<"You pressed F"<<endl;
        }
        else
            cout<<"You suck!";
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

例如,当我按D时,我只想接收You pressed D输出.相反,我得到了You pressed D You suck!

Luc*_*ore 8

我很确定你想要else if(即嵌套)而不是(后续)ifs,但这只是猜测,因为你没有提供任何输入或输出.