-3

What is Wrong in this code???.Compiler displays the message that no matching function for call to max(int&, int&, int&, int&)

#include<iostream>
 
 using namespace std;
 
 int main()
 {
     
     int a,b,c,d;
     cin>> a >> b >> c >>d;
     max(a,b,c,d);
 
    return 0;
 }
  int max(int a,int b,int c,int d) 
  {
      
      if(a>b && a>c && a>d)
      {
         return a;
      }
      else if(b>c && b>d)
      {
          return b;
          
      }
      else if(c>d)
      {
          return c;
      }
      else 
      {
          return d;
      }
  }  

selbie
  • 100,020
  • 15
  • 103
  • 173
  • 2
    Use forward declaration or define the function before main. Se e [Why can't a function go after Main](https://stackoverflow.com/questions/17675935/why-cant-a-function-go-after-main) – Jason Feb 26 '23 at 05:19
  • 1
    Also [stop using `using namespace std;`](https://www.youtube.com/watch?v=MZqjl9HEPZ8). For future reference have a look at [std::vector](https://en.cppreference.com/w/cpp/container/vector) and [std::max_element](https://en.cppreference.com/w/cpp/algorithm/max_element) – Pepijn Kramer Feb 26 '23 at 06:32

1 Answers1

0

Try declaring the function before using it.

You can do this by adding the following declaration before your definition of main()

int max(int a,int b,int c,int d);

You can also accomplish this by moving the definition of max() above main().

merlin2011
  • 71,677
  • 44
  • 195
  • 329