On line 20 of this code it tells me \"Error: a value type of \"int *\" cannot be
ID: 3652634 • Letter: O
Question
On line 20 of this code it tells me "Error: a value type of "int *" cannot be assigned to an entity type of "int **". How do I fix this?#include <iostream>
using namespace std;
int mode(int *arr,int n)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(arr[j]>arr[j+1])
{
int temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
int **mode;
mode=new (int*) [n];
for(int i=0;i<n;i++) mode[i]=new int[2];
for(int i=0;i<2;i++)
{
for(int j=0;j<n;j++)
{
mode[j][i]=0;
}
}
mode[0][0]=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(arr[i]==arr[j+1])
{
++mode[i][0];
mode[i][1]=arr[i];
}
}
}
int max;
int k=0;
max=mode[0][0];
for(int j=0;j<n;j++)
{
if(max<mode[j][0])
{
max=mode[j][0];
k=j;
}
}
if(max==1) return -1;
return mode[k][1];
}
int main()
{
int n;
cout<<"Enter the total integers to be stored in array: ";
cin>>n;
int *arr;
arr = new int[n];
cout<<"Enter integers: ";
for(int i=0;i<n;i++)
cin>>arr[i];
cout<<"mode is : ";
cout<<mode(arr,n)<<endl;
}
Explanation / Answer
// try this #include using namespace std; int mode(int *arr,int n) { for(int i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.