0

I am working on program that remove duplicates from an array I am using three functions here: one to take the input such as the size and the number, second function to remove duplicates and return the number without duplicates and the third function just a report show the size and the new number but I am having problem I don't know in what step I think in report or phillip erreur:

In function ‘int main()’: invalid conversion from ‘int*’ to ‘int’,initializing argument 1 of ‘void report(int, int)’

#include <iostream>
using namespace std;

const int size = 100;

void phillip(int[], int & );
/* Preconditions: Array of base type in declared and int varuable declared
   postconditions: the array is filled with values supllied by the user at
   the keybord. the user is assked how many values they want - this value is
   given to the second argument.
*/

int remdubs(int[], int noel);
/* Preconditions: An array of basetype int that  has noel values.
   postconditions: The number of unique elemts in the array is returned. The function removes all dubplicates inside the array.
*/

void report(int s, int d);

int main()
{
    int ruby[size];
    int numele, numuniq;

    phillip(ruby, numele);

    numuniq = remdubs(ruby, numele);

    report(ruby, numuniq);

    return 0;
}

void phillip(int[], int& )
{
    int s;
    cout << "\nHow many values you want? ";
    cin >> s;

    cout << "\nPlease input 10 integers, hitting return after each one \n";
    for (int i = 0; i < s; i++)
    {
        int num;
        cin >> num;
    }
}

int rembups(int sapphire[], int noel)
{
    for (int i = 0; i < noel; i++)
    {
        for (int j = i + 1; j < noel; j++)
        {

            if (sapphire[i] == sapphire[j])
            {
                for (int k = j; k < noel; k++)
                    sapphire[k] = sapphire[k + 1];

                noel--;

                j--;
            }
        }
    }
    return noel;
}

void report(int s, int d)
{
    cout << "\nYou entered " << s << "distinct numbers: " << d;
}
2
  • If this isn't homework I recommend using std::vector and std::unique. Even if it is homework I still recommend using them. Commented May 10, 2014 at 0:23
  • I have enough there i dont want to use vector i just want to fix that code Commented May 10, 2014 at 0:26

3 Answers 3

2

Can't explain it better than your error:

void report (int s, int d);

this function asks for two integer values, you're passing an array to it which, with decayed functionalities, will behave like an integer pointer

int ruby[size];
report (ruby, numuniq);

I'm unsure on the behavior of your program but you should rather do something like

report(ruby[0], numuniq);

that is: access the element of the array and feed it to the function

Sign up to request clarification or add additional context in comments.

Comments

0

Few problems with the code:

  • Report function should be expecting an array of integers rather than single integer
  • Try using human readable variable or function names
  • remdubs was renamed to rempubs in function definition
  • phillip function definition didn't have params defined properly
  • You have const int size but do not use it
  • remdups has a bug somewhere. I will leave that out as I am trying to fix other issues here.
  • There are better ways of finding duplicates than remdups. Please look at some other solutions.

I have fixed your code and provided it here on ideone

Comments

0

The error is in the function report, it asks for two integer and you are passing an array and an integer instead and again i don't think you need 2 parameters in the function report one would solve your purpose

void report(int d)
{
    cout << "\nYou entered <<d<<" distinct numbers";
}

that would solve your error but i don't think you would get your desired output

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.