function larger interger

Create a function called larger which takes two integers as its parameters and returns the larger of the two integers.

I think its set up right so far but I would like for it to display the larger interger with that function inserted. How could I do that?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  #include<iostream>
using namespace std;

 
int max(int num1, int num2) 
{
   
   int result;
 
   if (num1 > num2)
      result = num1;
   else
      result = num2;
 
   return result; 
}

int main()
{
    int num1, num2;
    cout << "Enter your first number: ";
    cin >> num1;
    
    cout << "Enter your second number:";
    cin >> num2;
    
    if (num1 > num2)
    cout << num1 << " is greater than  " << num2 << endl;
    
    return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  #include<iostream>
using namespace std;

 
int max(int num1, int num2) 
{
   
   int result;
 
   if (num1 > num2)
      result = num1;
   else
      result = num2;
 
   return result; 
}

int main()
{
    int num1, num2;
    cout << "Enter your first number: ";
    cin >> num1;
    
    cout << "Enter your second number:";
    cin >> num2;
    
    cout<<"The larger number is "<<max(num1,num2)<<endl;
    
    return 0;
}
thank you!
Topic archived. No new replies allowed.