#include <iostream>
using namespace std;

int main( )
{
    int num1 , num2 , num3;
  cout << "Please Enter Three Valid Integers Using The Keyboard";
  cin >>  num1 , num2 , num3;
  if {num1 => num2} && {num2 => num3} else num1 + num2;
  if {num2 => num1} && {num1 => num3} else num2 + num1;
  if {num3 => num1} && {num1 => num2} else num3 + num1;
  if {num3 => num2} && {num2 => num1} else num3 + num2;
  cout << " The Maximum Sum Of These Numbers Is: "<< num1 , num2, num3 endl;
  
  system("pause");
  Return 0 ;
}

can anyone tell me what seems to be wrong with it ?

i get the error - expected `(' before '{' token

can someone please run me through it and how i can fix it thanks :)

Hi

Your code will now compile, so you now can see your programs logic...

#include <iostream>
using namespace std;

int main()
{
  int num1 , num2 , num3;
  cout << "Please Enter Three Valid Integers Using The Keyboard\n";
  cout << "enter interger 1\n";
  cin >>  num1;
  cout << "enter interger 2\n";
  cin >>  num2;
  cout << "enter interger 3\n";
  cin >>  num3;

  //First IF statement
  if ((num1 >= num2) && (num2 >= num3))
  {
      // We only come if above condition is met
      // You need to read about logical operators

      // We need to do something here...
      std::cout << "First IF statement is met...\n" << std::endl;

  }
  else
  {
      // We end up here if the above condition is not met
      int sum1;
      sum1 = num1 + num2;
      std::cout << "First IF statement is not met" << std::endl;
  }

  //Second IF statement
  if ((num2 >= num1)  && (num1 >= num3))
  {

  }
  else
  {
      num2 + num1;
  }

  //Third IF statement
  if ((num3 >= num1)  &&  (num1 >= num2))
  {

  }
  else
  {
     num3 + num1;
  }
  //Four IF statement
  if ((num3 >= num2) && (num2 >= num1))
  {

  }
  else
  {
     num3 + num2;
  }

  cout << " The Maximum Sum Of These Numbers Is: "<< num1 << num2 << num3 << endl;

  system("pause");
  return 0 ;
}

OK now work through the program & there are still some corrections to do

commented: Don't fix peoples code. Guide them to their own solution. -3

I saw a major syntax error. Maybe you were thinking Java?

The proper syntax for an if statement is:

if (condition1, condition2, condition3...) {statement1; statement2;}

If it's simpler, here it is on several lines:

if (condition1, condition2, condition3...)
{
statement1;
statement2;
}

If you wanted something to be done if it were evaluated false, just add an else at the end, followed by braced code:

if (condition1, condition2, condition3...)
{
statement1;
statement2;
}
else
{
statement3;
statement4;
}

Notice that the if...else statement doesn't require a semicolon (;) after the braces... it acts like a function.

Try fixing up your code with the right syntax.

Remember - you need the conditions in parentheses (()) and the function in braces({}).

Also, something I just realized is that you have no function for the "if" and the else has no condition.

Hope that helps!

Hi emanfman,

I agree with MOST of your post, but the syntax you give for the "if" statement is, while it will probably compile, misleading at best.

There is no multiple conditions separated by commas in an "if" statement. The syntax of the multiple types of "if" statement is as follows:

if ( condition ) statement1;

if ( condition ) statement1; else statement2;

if ( condition )
{
   statement1;
   statement2;
}

if ( condition )
{
   statement1;
   statement2;
}
else
{
   statement3;
   statement4;
}

Only the "for" statement has three parts to it, and they are separated by semicolons and not commas.

Tom

Hi emanfman,

I agree with MOST of your post, but the syntax you give for the "if" statement is, while it will probably compile, misleading at best.

There is no multiple conditions separated by commas in an "if" statement. The syntax of the multiple types of "if" statement is as follows:

if ( condition ) statement1;

if ( condition ) statement1; else statement2;

if ( condition )
{
   statement1;
   statement2;
}

if ( condition )
{
   statement1;
   statement2;
}
else
{
   statement3;
   statement4;
}

Only the "for" statement has three parts to it, and they are separated by semicolons and not commas.

Tom

From the near JavaScript example he gave, with the conditions separated by &&, I use a comma because it makes the "if" statement true only if ALL the conditions are true. Technically, it is still correct to use the && though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.