Can someone kinda check this one to see what wrong with it?

#include <iostream>
using namespace std;

int ture ( int a[], int b[], int d);
int main ()
{
    int b [5]={1,2,3,4,5};
    int a [5] ={1,2,3,4,5};

    int total= ture(b, a, 5);
    cout << total << endl;
}
int ture ( int a[], int b[], int d)
{
    const double NUM = 10;
    for (int d = 0; d < 10; d++)
    {
        if (a[d] != b[d])
        {
            return false;
        }
    }
    return true;
}

The arrays are fine! Do you have another problem with the code?

Doesn't this for loop run past your arrays?

for (int d = 0; d < 10; d++)//arrays have five elements
{
...
}

This function returns int but you return boolean inside the function. What does this function accomplish?

int ture ( int a[], int b[], int d)
{
    const double NUM = 10;
    for (int d = 0; d < 10; d++)
    {
        if (a[d] != b[d])
        {
            return false;
        }
    }
    return true;
}

Edited 2 Years Ago by gerard4143

Try looking at the function here:

#include <iostream>

using namespace std;
int ture ( int a[], int b[], int d);

int main ()
{
    int b [5]={1,2,3,4,5};
    int a [5] ={1,2,3,4,5};

    cout << ture(b, a, 5) << endl;
}

int ture ( int a[], int b[], int d)
{
    for (int i = 0; i < d; i++)
    {
        if (a[i] != b[i])
        {
            return false;
        }
    }
    return true;
}
This article has been dead for over six months. Start a new discussion instead.