C++ 需要帮助修复程序的功能吗 int最小值(int x,int y,int z) { int=x; if(y

C++ 需要帮助修复程序的功能吗 int最小值(int x,int y,int z) { int=x; if(y,c++,C++,根据您的评论,您只需修复for循环的第一部分: int smallest(int x, int y, int z) { int smallest = x; if (y < smallest) smallest = y; if (z < smallest) smallest = z; return smallest; } void printmessage(int smallest) { int w = 0;

根据您的评论,您只需修复
for
循环的第一部分:

int smallest(int x, int y, int z)
{
    int smallest = x;
    if (y < smallest)
        smallest = y;
    if (z < smallest)
        smallest = z;
    return smallest;
}

void printmessage(int smallest)
{
    int w = 0;
    if(smallest < 0 || smallest >= 10)
        cout << "it is not possible to print the message in this case" << endl;
    else
    {
        for(w < 0 ||w > 10; w < smallest; w++)
            cout << "No" << endl;
        cout << endl << endl;
    }
}
产出:

#include <iostream>

void printmessage(int smallnum) {
    if(smallnum < 0 || smallnum >= 10) {
        std::cout << "it is not possible to print the message in this case"
                  << std::endl;
    } else {
        for(int w = 0; w < smallnum; ++w) {
            std::cout << "No" << std::endl;
        }
    }
}

int main(void) {
    printmessage(5);
    return 0;
}
for(w<0 | | w>10;w
这篇文章的第一部分实际上是毫无意义的,虽然该语句在技术上是执行的,但for循环中的第一条语句是用于初始化和/或分配循环控制变量的通俗说法。在您的例子中,您可能希望使用以下方法:

for(w < 0 ||w > 10; w < smallest; w++)
for(int w=0;w
这将初始化循环范围内的变量“w”,而不是函数范围内的变量(因此在循环退出后,“w”将被丢弃)。因为您只需要在循环内使用它,所以这应该是您要查找的

如果要检查w是否也不小于0或大于10,可以使用以下循环:

for(int w = 0; w < smallest; w++)
for(int w=0;w<0 | | w>10,w<最小值;w++)
如果以后需要(或在不需要循环控制变量的其他情况下),也可以在函数范围中保留初始w,并在循环声明的该空间中保留一个空白语句:

for(int w = 0; w < 0 || w > 10, w < smallest; w++)
(;w<最小值;w++)的


最小的(x,y,z)
可以替换为
std::min({x,y,z})
printmessage()
应该做什么?根据最小的整数打印一条消息,但是什么消息?如果您不指定它应该做什么,我们无法帮助您“修复”。消息“否”与最小整数的次数相同。如果它是5倍,则将打印5次。我得到| 30 |错误:从'int(*)(int,int,int)'到'int'[-fppermissive]|的转换无效,在第30行尝试将printmessage()放入main。和| 5 |错误:初始化'void printmessage(int)[-fppermissive]|的参数1,声明printmessage()@John:您还有一个名为
minimate
的函数,在
printmessage()
中更改参数的名称,请参见编辑。@John如果您的代码与OP中的代码相同,您试图将函数“minimate”作为参数传递,而不是传递结果,则应输入printmessage(minimate(x,y,z)),或将结果分配给变量并使用该变量。感谢您最终获得!忘记为最小值添加变量。
for(int w = 0; w < smallest; w++)
for(int w = 0; w < 0 || w > 10, w < smallest; w++)
for(; w < smallest; w++)