Q:

(newbie here) Range-based for loops in functions not working (C++)

I've been doing some C++ exercises and I stumbled upon this one problem with C++ for loops, which is a relatively new topic to me. I decided to make a function that takes an array of integers and provide a certain number, whether it is the maximum value, minimum value, the average of all numbers.
So I thought it would be a lot easier to make this for loop which doesn't take the array size at all! But... My compiler didn't like my idea. See the code below please (the functions are written in Portuguese, but it doesn't really matter at all):
#include <iostream>
#include <locale.h>
#include <math.h>
#include <iomanip>
#include <string>
#include <random>
#include <time.h>

using namespace std;

void juradosLegais(int v[]);
float notasGrandes(int v[]);
int piorNota(int v[]);
int melhorNota(int v[]);
float getMedia(int v[]);
void storeValues(int v[]);

int main() {
    setlocale(LC_ALL, "Portuguese");

    int notas[5];
    storeValues(notas);
    cout << "A maior nota foi " << melhorNota(notas) << " e a pior foi " << piorNota(notas) << "..." << endl;
    cout << "A média foi de " << getMedia(notas) << "." << endl;
    cout << notasGrandes(notas) << "% dos jurados foram legais." << endl;
    juradosLegais(notas);

    return 0;
}

void juradosLegais(int v[]) {
    int count = 0;
    for (int n : v ) {
        if (n == melhorNota(v))
            cout << "O jurado " << ++count << " foi bem legal com o atleta!" << endl;
    }
}

float notasGrandes(int v[]) {
    int soma = 0;
    int count = 0;
    for (int n : v[]) {
        if (n >= 8) {
            soma++;
        }
        count++;
    }
    return (soma / count) * 100;
}

int piorNota(int v[]) {
    int pior = v[0];
    for (int n : v[]) {
        n < melhor ? melhor = n;
    }
    return pior;
}

int melhorNota(int v[]) {
    int melhor = v[0];
    for (int n : v[]) {
        n > melhor ? melhor = n;
    }
    return melhor;
}

float getMedia(int v[]) {
    float sum = 0;
    int count = 0;
    for (int n : v[]) {
        sum += n;
        count++;
    }
    return sum / count;
}

void storeValues(int v[]) {
    int count = 0;
    for (int n : v[]) {
        cout << "Nota do jurado #" << ++count << ": ";
        cin >> n;
    }
}

And what the compiler says? These things:
error C3312: no callable 'begin' function found for type 'int []' (33)
error C3312: no callable 'end' function found for type 'int []' (33)
error C2065: 'n': undeclared identifier (34)
error C2059: syntax error: ']' (42)
error C2059: syntax error: '<end Parse>' (42)

Help me... please.

A:

If my memory serves me right, builtin arrays (like int notas[5];) don't work because they don't keep track of their size and don't have member functions (like begin and end) which are required for the range based for loops to work. Instead use the standard library array class to do this and pass it in. Then your for loops should work. So instead of:
int notas[5];

You would do:
std::array<int, 5> notas;

And instead of declaring your functions like this:
 void juradosLegais(int v[])

You could declare them like this:
 template <class arraytype>
 void juradosLegais(arraytype v)
 {
     ...
 }

Or this:
 void juradosLegais(std::array<int, 5> v)
 {
     ...
 }

Obviously, be sure to include the array header like so:
#include <array>

Better yet, don't use arrays of any sort and instead just use a vector. They are safer and more flexible and are generally as fast as arrays in most circumstances.

