我正在做一個問題,我必須通過一個函數傳遞數組,並返回用戶輸入的索引範圍內的最小整數。問題是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