if语句错误!

发布于 2024-11-24 23:31:28 字数 7313 浏览 1 评论 0原文

我收到以下错误:

错误:没有匹配的函数可用于调用“max(int&, int&, int&, int&)”

我的代码是:

#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);
}

我收到错误的行位于第 74 行:

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)

这都是 C++ 中的,以防万一看不到标签或识别不到代码。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

巨坚强 2024-12-01 23:31:28

max 仅获取两个参数,因此您必须通过多次调用来组合它。

int maxGd = max(max(manudgd,rmadgd),max(lagalgd,acmilgd));
if(maxGd == manudgd || maxGd == lagalgd || maxGd == acmilDg) {
    // ...
}

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) {
    // ...
}
可是我不能没有你 2024-12-01 23:31:28

std::max 采用两个参数,而不是任意数量的参数。

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

·深蓝 2024-12-01 23:31:28

max 有两个参数。您可能想查看max_element。顺便说一句,您的代码可能需要一些重构 - 请阅读清理代码罗伯特·C·马丁.

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.

眼眸里的快感 2024-12-01 23:31:28

这是因为没有带有四个参数的 max 函数。 max 仅采用两个参数。您可以使用已经存在的函数自己编写一个这样的函数:

int max(int a, int b, int c, int d) {
    return max(max(a,b),max(c,d));
}

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));
}
音盲 2024-12-01 23:31:28

在 C++ 中 std::max() 仅需要两个参数。

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

梦在深巷 2024-12-01 23:31:28

呃?据我所知,没有 max() 函数需要四个参数! 中有两个参数版本,std::max()

如果这是您自己的,请实施它。

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.

冷弦 2024-12-01 23:31:28

因为 C++ 中没有这样一个名为 max 的函数,它需要 4 个参数,而您还没有定义它!

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

栖迟 2024-12-01 23:31:28

我在代码中没有看到您实现了 max(int&, int&, int&, int&) 方法。

在 C++ 库中,您可以找到 std ::max() 声明如下:

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 );

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 );
痞味浪人 2024-12-01 23:31:28

max() 函数尚未在调用范围内定义。
添加定义并再次编译。

旁注:max() 在某些编译器中是一个宏,但有 2 个参数而不是 4 个。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文