#include <iostream>
using namespace std;
int main()
{
int positiveInteger;
cout << "Please input an integer up to 100." << endl;
cin >> positiveInteger;
int result = 0;
for (int i = 0; i <= positiveInteger; i++)
{
if (positiveInteger >= 0)
{
result += i;
}
else
{
cout << "Please input a positive integer." << endl;
}
}
cout << result;
return 0;
}
上記の私はfor
ループを持っています。中央にif else文があります。私は負の値ではない整数を入力すると、その結果をループするので、混乱しています。しかし、正の整数を入力してください。だから私はそれをif文で設定するのですが、上記の数値と= 0は結果を返しますが、負の数を入力すると、ただ0が得られます。「正の整数を入力してください。私は何が間違っているのか分かりません。 trueの場合はif文がifを引き出し、trueでない場合はelseを引き出しますか?または私は何かを逃していますか?else文が混乱している場合C++
待ち、私はちょうどそれが入力整数が正のthatsしてくださいと言うなぜ文句を言わない、まだ結果が0を返す実現しますが? – mystycs