2014-10-05 145 views
-4

我正在做一個問題,我必須通過一個函數傳遞數組,並返回用戶輸入的索引範圍內的最小整數。問題是cout不顯示函數的返回值被稱爲:cout不打印函數的返回值?

enter image description here

誰能告訴我什麼是錯了嗎?

#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; 
} 
+1

安置自己的輸出,而不是截圖和刪除';'在頭兩行 – 2014-10-05 02:23:14

+0

如果lowIndex不爲0時會發生什麼?我總是先設置爲0。 – 2014-10-05 02:23:59

+0

是的,我一開始設置爲lowIndex,但是我將它改爲0.我不知道我的腦袋裏發生了什麼。我拿出分號,但我仍然沒有得到我的功能輸出 – Nguyensane 2014-10-05 02:29:08

回答

-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; 
    .... 
} 
+0

謝謝,我的輸出仍然不會顯示我的lowestNum值,但? – Nguyensane 2014-10-05 02:36:08

+0

試試我的新版本。那麼你可能會看到這個問題。 – 2014-10-05 03:09:46