C++ Array List

crhodes2 profile image crhodes ・1 min read

I am trying to solve the algorithm of finding and displaying the largest age in the array. This is what I have so far.

#include <iostream>

using namespace std;

int main()
    int brothers[5] = {6,3,24,12,22};
    int i = 0;
    int eldestAge = 0;

    for (int j = 0; j < brothers[i]; ++j)
            if (eldestAge < brothers[i])
                eldestAge = brothers[i];
                // do nothing

        cout << "Eldest Age is = " + eldestAge << endl;


However the output doesn't display anything except the quote. Please let me know what am I doing wrong.

Posted on by:


markdown guide

It looks like you're trying to add a string and an int, when C++ does not automatically cast the int like say C# does.

Following this, you just need to change

cout << "Eldest Age is = " + eldestAge << endl;


cout << "Eldest Age is = " << eldestAge << endl;

Oh wow! Such stupid mistake I've made, lol! Thanks!
Now could you give me any ideas as to why the largest number is not displaying? What am I doing wrong? :/
Edit: Nevermind! Solved it!