-4

I got the following error:

error: no matching function for call to 'max(int&, int&, int&, int&)'

My code is:

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

int main()
{
    srand(time(NULL));
    int g1l= rand()%5;
    int g1r= rand()%5;
    int g2l= rand()%5;
    int g2r= rand()%5;
    int g3l= rand()%5;
    int g3r= rand()%5;
    int g4l= rand()%5;
    int g4r= rand()%5;
    int g5l= rand()%5;
    int g5r= rand()%5;
    int g6l= rand()%5;
    int g6r= rand()%5;
    int manudw = 0;
    int manudd = 0;
    int manudl = 0;
    int lagalw = 0;
    int lagald = 0;
    int lagall = 0;
    int rmadw = 0;
    int rmadd = 0;
    int rmadl = 0;
    int acmilw = 0;
    int acmild = 0;
    int acmill = 0;

    int manudp = ((manudw*3)+(manudd*1));
    int lagalp = ((lagalw*3)+(lagald*1));
    int rmadp = ((rmadw*3)+(rmadd*1));
    int acmilp = ((acmilw*3)+(acmild*1));
    string manud = "Manchester United";
    string lagal = "Los Angeles Galaxy";
    string rmad = "Real Madrid";
    string acmil = "AC Milan";
    string place1 = "Manchester United  |";
    string place2 = "Real Madrid        |";
    string place3 = "AC Milan           |";
    string place4 = "Los Angeles Galaxy |";
    int counter=0;
    int round1;
    int round2;
    int round3;
    int manudgd = 0;
    int rmadgd = 0;
    int acmilgd = 0;
    int lagalgd = 0;
    do
    {
        int manudp = ((manudw*3)+(manudd*1));
        int lagalp = ((lagalw*3)+(lagald*1));
        int rmadp = ((rmadw*3)+(rmadd*1));
        int acmilp = ((acmilw*3)+(acmild*1));
        int manudgd = ((g1l+g3r+g6r)-(g1r+g3l+g6l));
        int rmadgd = ((g2l+g3l+g5r)-(g2r+g3r+g5l));
        int acmilgd = ((g2r+g4l+g6l)-(g2l+g4r+g6r));
        int lagalgd = ((g1r+g4r+g5l)-(g1l+g4l+g5r));
        cout<<place1<<" "<<manudw<<" | "<<manudd<<" | "<<manudl<<" | "<<manudp<<" | "<<manudgd<<"  |"<<endl<<
              place2<<" "<<rmadw<<" | "<<rmadd<<" | "<<rmadl<<" | "<<rmadp<<" | "<<rmadgd<<"  |"<<endl<<
              place3<<" "<<acmilw<<" | "<<acmild<<" | "<<acmill<<" | "<<acmilp<<" | "<<acmilgd<<"  |"<<endl<<
              place4<<" "<<lagalw<<" | "<<lagald<<" | "<<lagall<<" | "<<lagalp<<" | "<<lagalgd<<"  |"<<endl<<endl;
//        if(max(manudgd,rmadgd,lagalgd,acmilgd)==manudgd || max(manudgd,rmadgd,lagalgd,acmilgd)==rmadgd || max(manudgd,rmadgd,lagalgd,acmilgd)==lagalgd || max(manudgd,rmadgd,lagalgd,acmilgd)==acmilgd)
        if(counter==0)
        {
            for(round1=0;round1<=0;round1++)
            {
                cout<<"Manchester United "<<g1l<<"-"<<g1r<<" Los Angeles Galaxy"<<endl;
                cout<<"Real Madrid "<<g2l<<"-"<<g2r<<" AC Milan"<<endl<<endl;
                int manudgd = ((g1l)-(g1r));
                int rmadgd = ((g2l)-(g2r));
                int acmilgd = ((g2r)-(g2l));
                int lagalgd = ((g1r)-(g1l));
                if(g1l>g1r)
                {
                    manudw++;
                    lagall++;
                }
                else if(g1l<g1r)
                {
                    lagalw++;
                    manudl++;
                }
                else if(g1l==g1r)
                {
                    manudd++;
                    lagald++;
                }
                if(g2l>g2r)
                {
                    rmadw++;
                    acmill++;
                }
                else if(g2l<g2r)
                {
                    rmadl++;
                    acmilw++;
                }
                else if(g2l==g2r)
                {
                    rmadd++;
                    acmild++;
                }
            }
        }
        else if(counter==1)
        {
            for(round2=0;round2<=0;round2++)
            {
                cout<<"Real Madrid "<<g3l<<"-"<<g3r<<" Manchester United"<<endl;
                cout<<"AC Milan "<<g4l<<"-"<<g4r<<" Los Angeles Galaxy"<<endl<<endl;
                int manudgd = ((g1l+g3r)-(g1r+g3l));
                int rmadgd = ((g2l+g3l)-(g2r+g3r));
                int acmilgd = ((g2r+g4l)-(g2l+g4r));
                int lagalgd = ((g1r+g4r)-(g1l+g4l));
                if(g3l>g3r)
                {
                    rmadw++;
                    manudl++;
                }
                else if(g3l<g3r)
                {
                    manudw++;
                    rmadl++;
                }
                else if(g3l==g3r)
                {
                    manudd++;
                    rmadd++;
                }
                if(g4l>g4r)
                {
                    acmilw++;
                    lagall++;
                }
                else if(g4l<g4r)
                {
                    acmill++;
                    lagalw++;
                }
                else if(g4l==g4r)
                {
                    lagald++;
                    acmild++;
                }
            }
        }
        else if(counter==2)
        {
            for(round3=0;round3<=0;round3++)
            {
                cout<<"Los Angeles Galaxy "<<g5l<<"-"<<g5r<<" Real Madrid"<<endl;
                cout<<"AC Milan "<<g6l<<"-"<<g6r<<" Manchester United"<<endl<<endl;
                int manudgd = ((g1l+g3r+g6r)-(g1r+g3l+g6l));
                int rmadgd = ((g2l+g3l+g5r)-(g2r+g3r+g5l));
                int acmilgd = ((g2r+g4l+g6l)-(g2l+g4r+g6r));
                int lagalgd = ((g1r+g4r+g5l)-(g1l+g4l+g5r));
                if(g5l>g5r)
                {
                    lagalw++;
                    rmadl++;
                }
                else if(g5l<g5r)
                {
                    rmadw++;
                    lagall++;
                }
                else if(g5l==g5r)
                {
                    lagald++;
                    rmadd++;
                }
                if(g6l>g6r)
                {
                    acmilw++;
                    manudl++;
                }
                else if(g6l<g6r)
                {
                    acmill++;
                    manudw++;
                }
                else if(g6l==g6r)
                {
                    manudd++;
                    acmild++;
                }
            }
        }
        counter++;
    }
    while(counter!=4);
}

The line I got the error on was on the 74th line:

if(max(manudgd,rmadgd,lagalgd,acmilgd)==manudgd || max(manudgd,rmadgd,lagalgd,acmilgd)==rmadgd || max(manudgd,rmadgd,lagalgd,acmilgd)==lagalgd || max(manudgd,rmadgd,lagalgd,acmilgd)==acmilgd)

This was all in C++ just in case you don't see the tags or recognize the code.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Bob
  • 166
  • 3
  • 15
  • 1
    What exactly is your question? Where are you expecting the max function to come from? – Marcin Jul 18 '11 at 13:58
  • 1
    Welcome to Stack Overflow, Bob. It's nice that you read how to embed code in a question; thanks for that. It's not so nice is that you embedded **lots** of code in your question. Try to present a minimal example next time around. And once again, welcome aboard. – David Hammen Jul 18 '11 at 13:58
  • 1
    It's good that you've pasted a block of code that's complete enough to reproduce your error, but it would have been better if you could have cut it down so it was a minimal block of code that gives the same error. – Andrew Aylett Jul 18 '11 at 13:59
  • 4
    Sweet merciful Gods, my poor useless eyes! – Anthony Jul 18 '11 at 13:59
  • Time to pick up a C++ beginners book and read it thoroughly. I recommend Herbert Schildt "Complete Reference" (though there might be better books, that others can recommend. I can only recommend what I know). – Outspoken Jul 18 '11 at 15:30
  • 2
    `stdlib.h` and friends are deprecated in C++. Use `cstdlib` and friends, and throw away whatever useless book you're using. Get [a real one](http://jcatki.no-ip.org/fncpp/Resources). Also, whilst I'm here..... jesus christ.... – Lightness Races in Orbit Jul 19 '11 at 23:53

9 Answers9

6

max gets just two arguments, so you have to composite it from multiple calls.

int maxGd = max(max(manudgd,rmadgd),max(lagalgd,acmilgd));
if(maxGd == manudgd || maxGd == lagalgd || maxGd == acmilDg) {
    // ...
}
marc
  • 6,103
  • 1
  • 28
  • 33
4

std::max takes two arguments, not an arbitrary number of arguments.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
David Hammen
  • 32,454
  • 9
  • 60
  • 108
2

max takes two arguments. You may want to see max_element. By the way, your code may need some refactoring - please read Clean Code from Robert C. Martin.

ron
  • 9,262
  • 4
  • 40
  • 73
  • 1
    No, I think he needs to read something more *basic* first: http://stackoverflow.com/q/388242/46642 – R. Martinho Fernandes Jul 18 '11 at 14:01
  • @Martinho: I think general coding style and C++ (or any language)-specific knowledge is largely orthogonal, and so can be learnt in parallel. – ron Jul 18 '11 at 14:04
1

That's because there is no max function that takes four arguments. max takes only two arguments. You can write one such function yourself, using the one that already exists:

int max(int a, int b, int c, int d) {
    return max(max(a,b),max(c,d));
}
R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
0

In C++ std::max() takes only two arguments.

Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171
0

Eh? There is no max() function that I am aware of which takes four arguments! There is a two arg version, std::max() in <algorithm>.

If this is your own, implement it.

Nim
  • 33,299
  • 2
  • 62
  • 101
0

Because there is no such function called max that takes 4 arguments in the c++ and you haven't defined one!

bluefalcon
  • 4,225
  • 1
  • 32
  • 41
  • oh, I thought I saw the max function before in c++ =/ – Bob Jul 18 '11 at 13:58
  • well there is one, as other have already pointed out, but it takes only 2 arguments not 4. You can implement your own or use the std one as shown by @marc. – bluefalcon Jul 18 '11 at 14:00
0

I don't see in the code where you've implemented max(int&, int&, int&, int&) method.

In C++ <algorithm> library, you can find std::max() declared as follows:

template <class T> const T& max ( const T& a, const T& b );
template <class T, class Compare>
  const T& max ( const T& a, const T& b, Compare comp );
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
0

The max() function has not been defined in the scope of the call. Add a definition and compile again.

Side note: max() is a macro in some compilers, but then with 2 arguments instead of 4.

Marcel
  • 61
  • 2