2016-10-11 56 views
0

我想通过使用函数从数组中返回最高值,但我似乎无法让它正常工作,可以有人帮助。所以我想显示在数组1,2,3和4中的最高值,但我似乎无法让该函数工作。数组函数C++发现最高值

#include "stdafx.h" 
#include <iostream> 
using namespace std; 

void averScore(int test[], int size); 
void highScore(int test[], int size); 
void lowestScore(int test[], int size); 



int main() 
{ 

    const int SIZE1 = 5; 
    const int SIZE2 = 6; 
    const int SIZE3 = 4; 
    const int SIZE4 = 5; 

    int set1[SIZE1] = { 90,85, 88, 80, 85 }; 
    int set2[SIZE2] = { 89, 75, 78, 82, 83, 80 }; 
    int set3[SIZE3] = { 88, 82, 88, 90 }; 
    int set4[SIZE1] = { 85, 87, 88, 90, 92 }; 

    highScore(set1, SIZE1); 

    return 0; 
} 

void highScore(int num[], int size) 
{ 
    int highnum = 0; 

    for (int i = 0; i < size; i++) 
    { 
     if (num[i] > highnum) 
      highnum = num[i]; 
     cout << num[i]; 
    } 
    cout << highnum; 
} 
+1

请澄清什么是不准确的工作后,添加一个新行endl,什么是你 –

+0

看起来正确的结果/错误...有什么问题吗? – DigitalNinja

+0

究竟是什么错误?你应该使用[std :: array](http://en.cppreference.com/w/cpp/container/array)和[std :: max_element](http://en.cppreference.com/w/cpp/算法/ max_element)。 –

回答

0

您只为SET1调用了“highScore”函数。

如果你想要所有四个,你必须调用每个集合的函数。

0

我不知道你是否需要stdafx.h库。对我而言,它没有包含它就很好用。

而且cout声明这样cout << num[i] << endl;cout << highnum << endl;