ユーザーの入力が前のif状態を満たしていれば、次のelse if文にコードを移動させる方法がわかりません。C++でスキップする方法
#include <iostream>
using namespace std;
int main()
{
double input;
cout << "Time Calculator\n Enter the number of Seconds: " << endl;
cin >> input;
if (input < 60)
{
cout << "The time is " << input << " seconds." << endl;
}
else if (input >= 60)
{
cout << "The time is " << input << " minutes." << endl;
}
else if (input >= 3600)
{
cout << "The time is " << input << " hours." << endl;
}
else if (input >= 86400)
{
cout << "The time is " << input << " days." << endl;
}
return 0;
}
'入力> = 3600 &&入力<86400 'または' input> = 60 && input <3600' – Smit
あなたは 'if'と' else if'の目的を理解しましたか?これはどちらかのチェックのようなもので、1つのコードブロックしか実行されません。あなたは正確に何を達成しようとしていますか? –
条件の順序を逆にすると、問題は、> = 86400が> 60、> = 3600などのすべての条件を満たしていることです。 –