【问题标题】:I can`t call the bool function in c++ (closed)我不能在 C++ 中调用 bool 函数(关闭)
【发布时间】:2020-01-06 20:10:02
【问题描述】:

大家好,请帮我解决这个问题

#include <iostream>
using namespace std;

bool puzzle(int size, int array[], int start)
{
    cout <<"how many blocks you want for the puzzle? \n";
    cin >> size;
    for (int i = 0; i < size; i++)
    {
        cout << "enter your numbers in order for the blocks:\n";
            cin >> array[i];
            if (array[0] > size) { return false; };
            if (array[0] == size) { return true; };
    }
}

int main()
{

      puzzle;
    return 0;
}





【问题讨论】:

  • 给定你用来学习这门语言的任何资源(无论是教授、教程网站还是书籍),它们是如何教你调用函数的?
  • 您的程序存在多个问题。我建议你先写一些更简单的东西,例如一个从main 调用的函数,它只打印Hello world!,没有别的。你知道你会怎么做吗?
  • puzzle; 不会调用您的函数。您的函数需要 3 个参数。你什么都不提供。
  • 听起来你可以使用good C++ book
  • @makankananian "在我之前调用 void 函数,如 "puzzle()" 但如果使用它,它会说参数太少,我无法运行程序" 多少参数puzzle 有吗? puzzle() 传递了多少?

标签: c++ function boolean


【解决方案1】:

您的函数具有参数,因此您需要调用它们才能使其工作。在这种情况下(一个例子):

int size = 5;
int array[5];
int start = 0;

puzzle(size, array, start);

【讨论】:

    猜你喜欢
    • 2013-08-17
    • 1970-01-01
    • 2012-11-26
    • 2021-03-27
    • 1970-01-01
    • 1970-01-01
    • 2020-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多