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?
 
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

}
0
 
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

 }
0
 
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.


0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
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.


0
 
DarrylshCommented:
oh wait the braces don't match... but still the variable names need to match
0
 
jkrCommented:
???
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.