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;
}
请澄清什么是不准确的工作后,添加一个新行
endl
,什么是你 –看起来正确的结果/错误...有什么问题吗? – DigitalNinja
究竟是什么错误?你应该使用[std :: array](http://en.cppreference.com/w/cpp/container/array)和[std :: max_element](http://en.cppreference.com/w/cpp/算法/ max_element)。 –