我正在开发从数组中删除重复项的程序 我在这里使用了三个函数:一个用于获取输入,例如大小和数字,第二个函数用于删除重复项并返回没有重复项的数字,第三个函数只是一份报告显示了大小和新数字,但我遇到了问题,我不知道我在报告或 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;
}
最佳答案
无法比您的错误更好地解释它:
void report (int s, int d);
这个函数要求两个整数值,你传递一个数组给它,随着功能的衰退,它的行为就像一个整数指针
int ruby[size];
report (ruby, numuniq);
我不确定你的程序的行为,但你应该做类似的事情
report(ruby[0], numuniq);
即:访问数组的元素并将其提供给函数
关于c++ - 编写程序删除数组中的重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23575813/