C ++如果/ else打印出两个输出

时间:2015-06-16 18:06:20

标签: c++

我的if / then声明出了问题。它打印出两个couts ......

  devise_for :users, skip: [:session, :password, :registration, :confirmation], controllers: { omniauth_callbacks: 'omniauth_callbacks' }

  scope '(:locale)', locale: /en|zh/ do
    devise_for :users, skip: :omniauth_callbacks

    devise_scope :user do
      get 'auth/:provider/setup' => 'omniauth_callbacks#setup'
    end
  end

我不确定我做错了什么...... 任何建议? 谢谢!

2 个答案:

答案 0 :(得分:2)

您的代码有拼写错误

if (averageScore >= 60)
{
    cout << "P\n";
}
else if (averageScore <= 59) // this line
{
    cout << "F\n";
    cout << studentsName << " needs " << (60.0 - averageScore) << " additional points to pass the class.\n";
}

但是,由于您正在针对averageScore测试60,因此您可以将代码简化为(假设,averageScore是@Amol建议的整数)

if (averageScore >= 60)
{
    cout << "P\n";
}
else
{
    // if average score is an integer and it was not >= 60,
    // then it must implicitly be <= 59
    cout << "F\n";
    cout << studentsName << " needs " << (60.0 - averageScore) << " additional points to pass the class.\n";
}

如果averageScore不是整数,并且您想忽略averageScore&gt;的情况。 59但是&lt; 60(例如59.5)

else if (averageScore <= 59)
{
    ...
}

答案 1 :(得分:0)

else (averageScore <= 59);在没有任何代码的情况下制作else部分。删除;,您只需使用else。在代码中,else (averageScore <= 59)是错误的。如果您要为else添加条件,请使用else if