我正在做一个问题,我必须通过一个函数传递一个数组,并返回用户输入的索引范围内的最小整数。问题是cout
没有显示被调用函数的返回值:
有人能告诉我什么是错的吗?
#include <iostream>;
#include <array>;
using namespace std;
int minInARange (int array[], int lowIndex, int highIndex);
int main()
{
int myArray[15];
for (int i = 0; i <15; i++)
{
myArray[i] = 15 + rand() % (55 - 15 + 1);
}
for (int i = 0; i < 15; i++)
{
cout << myArray[i] << " ";
}
cout << endl;
int lowIndex = 0;
int highIndex = 0;
cout << "Enter in a low index of the array (0-14): " << endl;
cin >> lowIndex;
cout << "Enter in a higher index of the array (0-14): " << endl;
cin >> highIndex;
cout << "The lowest number in the range of array indices is: ";
cout << minInARange(myArray, lowIndex, highIndex) << endl;
return 0;
}
int minInARange (int array[], int lowIndex, int highIndex)
{
int lowestNum = array[lowIndex];
for (int i = 0; i < highIndex - lowIndex; i++)
{
if (array[i] < lowestNum)
{
lowestNum = array[i];
}
}
return lowestNum;
}
答案 0 :(得分:-1)
int minInARange (int array[], int lowIndex, int highIndex) {
cout << "lo:" << lowIndex << " hi:" << highIndex << endl;
for (int i=lowIndex; i<highIndex; i++) //maybe <=, depends what you want
cout << "Tock:" << i << endl;
....
}