-1

所以我刚开始编程,我不知道为什么我的代码不起作用,错误说它有错误但我不明白。我试图在这里和 Youtube 上查找它,但我似乎无法回答。这是代码:

#include <iostream>


using namespace std;

int main ()
{
int num1, num2 ,num3 , num4, num5;
//Assigning numbers
cout << "Give me 5 positive numbers, and then I'll add them up."<<endl;
cout << "Input first number: ";
cin >> num1;
cout << "Input second number: ";
cin >> num2;
cout << "Input third number: ";
cin >> num3;
cout << "Input fourth number: ";
cin >> num4;
cout << "Input fifth number: ";
cin >> num5;
int result;
//Adding the numbers
if ((num1, num2, num3, num4, num5 = - )){
cout << "Error";
}else{
result = num1 + num2 + num3 + num4 + num5;
cout << "The sum of the five numbers are " << result << ".";
}

return 0;
}
4

1 回答 1

1
if ((num1, num2, num3, num4, num5 = - ))

你不能以这种方式在 if 中传递条件。如果喜欢,有很多方法可以传递多重条件。

  • 通过类似的逻辑操作将它们分开 if (num < 0 || num2 < 0 || num3 <0 || num5 < 0 || num5 <0)
于 2020-12-17T12:41:06.690 回答