Question

#include <iostream>


using namespace std;

class amin
{
private:
    const int length = 10;
    int newArray[length];
    int i;

public:
    int deleteEvenNumber(int getArray[length])
    {

        for (i = 0 ; i < length ; i++)
        {
            if (getArray[i] % 2 == 0)
                newArray[i] = getArray[i];
                i++;

        };

        return newArray[length];
    };
};

main:

int main()
{
    amin manipulateArrays;

    int input , i = 0;
    const int length = 10;
    int mainArray[length];


    cout<<"Please enter ten numbers :"<<endl;

    for (i = 0 ; i < length ; i++)
    {
        cin>>input;
        mainArray[i] = input;
        i++;
    };

    manipulateArrays.deleteEvenNumber(mainArray[length]);
};

i got these two errors:

  1. error C2664: 'amin::deleteEvenNumber' : cannot convert parameter 1 from 'int' to 'int []'

  2. IntelliSense: argument of type "int" is incompatible with parameter of type "int *"

please help and explain about my mistake to me.

and please introduce a good tutorial for this problem or this title to me.

Was it helpful?

Solution

Your function deleteEvenNumber() requires an int [] (i.e. int array), however you passed it an int to it.

manipulateArrays.deleteEvenNumber(mainArray[length]);
                                  ^^^^^^^^^^^^^^^^^
                                         |
                            this is an 'int', not an 'int []'

To also pass the length to the function, you may want to change your function to

int deleteEvenNumber(int getArray[], int length)

And then call it like:

manipulateArrays.deleteEvenNumber(mainArray, length);

Alternatively, you can use vector<int> mainArray instead, and then you can easily get its length by mainArray.size().

OTHER TIPS

your function takes an int[](array) as a parameter

int deleteEvenNumber(int getArray[length])

but you're passing an int

manipulateArrays.deleteEvenNumber(mainArray[length]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top