2014-10-05 120 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