Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;运行时添加两个数组项和其他错误_C++_Arrays_Sum - Fatal编程技术网

C++ C++;运行时添加两个数组项和其他错误

C++ C++;运行时添加两个数组项和其他错误,c++,arrays,sum,C++,Arrays,Sum,当我编译和运行这个程序时,我会遇到不同的错误,主要是关于函数的调用和数组的总和——我自己也尝试过修复它们,但每当我修复一个问题时,我似乎永远都无法修复所有的错误,因为更多的问题进来了,然后离开了 /* Even Fibonacci numbers Problem 2 Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the

当我编译和运行这个程序时,我会遇到不同的错误,主要是关于函数的调用和数组的总和——我自己也尝试过修复它们,但每当我修复一个问题时,我似乎永远都无法修复所有的错误,因为更多的问题进来了,然后离开了

/*
Even Fibonacci numbers
Problem 2
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
*/

#include <iostream>
#include <string>

using namespace std;

int increaseArray(int array, int currentPointer, int maxNumber, int arraySize, bool stop, int total);

int main () {
  int arraySize = 2;
  int maxNumber = 4000000;
  int currentPointer = 1;
  int array[2] = {1, 2};
  int total = 0;
  bool stop = false;
  while (not stop) {
    increaseArray(array, currentPointer, maxNumber, arraySize, stop, total);
  }


}

int increaseArray(int array, int currentPointer, int maxNumber, int arraySize, bool stop, int total) {
  int newValue = array[currentPointer - 1] + array[currentPointer - 2];
  while (newValue < maxNumber) {
    arraySize++;
    int *array = new int[arraySize];
    array[arraySize] = newValue;
    if (newValue % 2 == 0) {
       total += newValue;
increaseArray(array, currentPointer, maxNumber, arraySize, stop, total);
}
  stop = true;
  return total;
  }

 };
/*
偶斐波那契数
问题2
斐波那契序列中的每个新项都是通过将前两项相加生成的。从1和2开始,前10个术语将是:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
通过考虑Fibonacci序列中值不超过400万的项,求偶数值项之和。
*/
#包括
#包括
使用名称空间std;
int递增数组(int数组、int currentPointer、int maxNumber、int arraySize、bool stop、int total);
int main(){
int-arraySize=2;
int maxNumber=4000000;
int currentPointer=1;
int数组[2]={1,2};
int-total=0;
bool-stop=false;
同时(不停止){
递增数组(数组、currentPointer、maxNumber、arraySize、stop、total);
}
}
int递增数组(int数组、int currentPointer、int maxNumber、int arraySize、布尔停止、int total){
int newValue=数组[currentPointer-1]+数组[currentPointer-2];
while(newValue
以下是我得到的错误:-

错误:调用“increaseArray”时没有匹配的函数 递增数组(数组、currentPointer、maxNumber、arraySize、stop、total); ^~~

注意:候选函数不可行:没有已知的第一个参数从“int[2]”到“int”的转换 int递增数组(int数组、int currentPointer、int maxNumber、int arraySize、bool stop、int total); ^ 错误:下标值不是数组、指针或向量 int newValue=数组[currentPointer-1]+数组[currentPointer-2]; ~^~~~~

错误:下标值不是数组、指针或向量 int newValue=数组[currentPointer-1]+数组[currentPointer-2]; ~^~~~~

错误:调用“increaseArray”时没有匹配的函数 递增数组(数组、currentPointer、maxNumber、arraySize、stop、total); ^~~

注:候选函数不可行:第一个参数没有从“int”到“int”的已知转换;将论点与 int递增数组(int数组、int currentPointer、int maxNumber、int arraySize、布尔停止、int total){ ^
生成4个错误。

问题在于increaseArray函数的声明。 您希望将整个数组作为参数传递,但您声明第一个参数只是一个整数。 解决这个问题的一个办法是: 整数递增数组(整数*数组,…)。 我强烈建议您了解更多有关将数组传递给函数的信息。 一个好的起点是:
我希望这会有帮助!

错误消息会准确地告诉您错误所在:
int-increaseArray(int-array,
应该是
int-increaseArray(int*array,
)。更改参数没有帮助。
int-array[2]
是一个固定大小的数组,不能“增加”。您可能需要尝试使用
std::vector