我正在做一个问题,我必须通过一个函数传递数组,并返回用户输入的索引范围内的最小整数。问题是cout
不显示函数的返回值被称为: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;
}
安置自己的输出,而不是截图和删除';'在头两行 – 2014-10-05 02:23:14
如果lowIndex不为0时会发生什么?我总是先设置为0。 – 2014-10-05 02:23:59
是的,我一开始设置为lowIndex,但是我将它改为0.我不知道我的脑袋里发生了什么。我拿出分号,但我仍然没有得到我的功能输出 – Nguyensane 2014-10-05 02:29:08