My job is to make a program that reads in 10 numbers, and only send out the distinct ones in the end. I am getting a semantic error, no matching call to function. Can anyone help me? Thanks.
// read in 10 numbers
// if they are distinct, keep them
// if not, dispose of them
#include <iostream>
#include <algorithm>
usingnamespace std;
constint SIZE = 4; // easier for testing
int final_list[SIZE];
int initial_list[SIZE];
void distinction (int n, bool exists);
int main()
{
int number;
cout << "Enter a list of ten numbers: " << endl;
for (int i = 0; i < SIZE; i++)
{
cin >> number;
initial_list[i] = number;
for (int i = 0; i < SIZE; i++)
cout << " initial list " << initial_list[i] << " ";
cout << endl;
distinction(number); // error here
for (int i = 0; i < SIZE; i++)
cout << "Distinct numbers are: " << final_list[i];
}
return 0;
}
void distinction (int n, bool exists)
{
for (int i = 0; i < SIZE; i++)
{
int n = initial_list[i]; // this is the value you are searching for
bool exists = std::any_of(std::begin(initial_list), std::end(initial_list), [&](int i)
{
return i == n;
});
if (exists == false)
final_list[i] = n;
elsebreak;
}
}
Line 14 - You declare distinction to take 2 arguments.
Line 33 - You call distinction with only one argument.
Line 56 - You attempt to return a boolean value from a void function.