-1

so I just started programming and I don't know why my code doesn't work, the error says that it has an error but I don't get it. I tried to look it up on here and Youtube but I can't seem to an answer. Here's the code :

#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;
}
  • 3
    What is your intention with that `if` statement? That is not valid C++ syntax. – costaparas Dec 17 '20 at 12:42
  • 2
    As a learning tool, a book still beats making some exercises and asking here. See https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – stefaanv Dec 17 '20 at 12:51
  • What led you to believe that `if ((num1, num2, num3, num4, num5 = - ))` is even valid C++ syntax, let alone that it would test if any of the variables `num1` to `num5` are negative??? – Peter Dec 17 '20 at 12:54

1 Answers1

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

You can not pass conditions in if in this way. There are many ways to pass muliple condition in if like.

  • Separate Them via some logical operation like if (num < 0 || num2 < 0 || num3 <0 || num5 < 0 || num5 <0) like that.
Umar Farooq
  • 418
  • 2
  • 14