C++ Function

I got error ... can someone help....

here is the code


#include <iostream>

using namespace std;

// prototype for function max3


int max3(int, int,int);

 
// function max3 takes three integer values and returns the largest

int max3(int num1, int num2, int num3)


{


    int maxint; // local variable



 if(n1>n2){
  if(n1>n3) return n1;
  else return n3;
 }
 {
 else{
  if(n2>n3) return n2;
  else return n3;
 
 }
void main()


 {
 cout << "Enter integer value 1 => " ; // ask user to enter three integer values

    cin >> n1;

    cout << "Enter integer value 2 => " ;

    cin >> n2;

    cout << "Enter integer value 3 => " ;

    cin >> n3;

     cout << "The max is " << max3(n1,n2 n3) << endl;  // display the maximum of the entered integers using max3 function
}
 }
mhhoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
1st of all you need to declare your variables and return the values correctly from your function. Also, the curly braces should match, e.g.

int max3(int num1, int num2, int num3)


{


    int maxint; // local variable



 if(n1>n2){
  if(n1>n3) maxint = n1;
  else maxint =  n3;
 }

 else{
  if(n2>n3) maxint = n2;
  else maxint = n3;
 
 }

 return maxint;
}
void main()


 {

int n1,n2,n3; // was missing

 cout << "Enter integer value 1 => " ; // ask user to enter three integer values

    cin >> n1;

    cout << "Enter integer value 2 => " ;

    cin >> n2;

    cout << "Enter integer value 3 => " ;

    cin >> n3;

     cout << "The max is " << max3(n1,n2 n3) << endl;  // display the maximum of the entered integers using max3 function

 }
brettmjohnsonCommented:
You have mis-balanced braces.  The max3() function is missing a closing curly brace, and main() has one too many.  Consider using a programmer's editor that automatically indents code and matches braces/brackets/parenthesis to avoid such obvious errors.


DarrylshCommented:
In your function's parameter list you have num1, num2, num3 but in the function body you have n1, n2, n3.

The braces match, I think it's just the weird formatting that makes it look like it doesn't.


CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

DarrylshCommented:
oh wait the braces don't match... but still the variable names need to match
DarrylshCommented:
You are also missing a comma in your last cout statement:
Here is the fixed code

#include <iostream>
using namespace std;

int max3(int n1, int n2, int n3)
{
    int maxint; // local variable
    if(n1>n2)
    {
        if(n1>n3) maxint = n1;
        else maxint =  n3;
    }

    else
    {
        if(n2>n3) maxint = n2;
        else maxint = n3;
    }
    return maxint;
}
int main()
{

    int n1,n2,n3; // was missing
    cout << "Enter integer value 1 => " ; // ask user to enter three integer values
    cin >> n1;
    cout << "Enter integer value 2 => " ;
    cin >> n2;
    cout << "Enter integer value 3 => " ;
    cin >> n3;
    cout << "The max is " << max3(n1,n2, n3) << endl;  // display the maximum of the entered integers using max3 function

}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkrCommented:
???
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.