# error: invalid conversion from 'int' to 'int*'

• 02-21-2011
csharp100
error: invalid conversion from 'int' to 'int*'
Hi everyone, on line 76 I get the error of an invalid conversion from and int to *int. Please bear in mind the function prototype for findmax must be the way it is. Can anyone help me? I appreciate it.
Code:

```#include <iomanip> #include <iostream> using namespace std; #define MAX 100 bool isAscending (int *a, int len); bool isDescending (int *a, int len); bool isInOrder (int *a, int len); double avg (const int *x, int len); int *findmax (const int *x, int n); int getInfo (int *a, int max); int total (const int *a, int len); void sort (int *x, int n); void swap (int &x, int &y); int main() {     int a[MAX];     int i = 0;     int len;     len = getInfo (a, MAX);     double x = avg (a, len);     if (len > 0) cout << "Avg: " << x << endl;     for (;i < len; i++) cout << setw(4) << *(a+i);     cout << endl;     if (isInOrder(a, len)) cout << "its in order" << endl;     else sort(a, len);     if (isInOrder(a, len)) cout << "its in order" << endl;     for (i = 0; i < len; i++) cout << setw(4) << *(a+i);     cout << endl;     return 0; } bool isAscending (int *a, int len) {     for (int i = 0; i < len - 1; i++)         if (*(a+i) > *(a+i+1)) return false;     return true; } bool isDescending (int *a, int len) {     for (int i = 0; i < len - 1; i++)         if (*(a+i) < *(a+i+1)) return false;     return true; } bool isInOrder (int *a, int len) {     return isAscending(a, len) || isDescending(a, len); } double avg(const int * a, int len) {     int tot = total(a,len);     return (double)tot / len; } int *findmax(const int *x, int n) {     int temp = 0;     int i = 1;     while (i <= n)     {         if (*(x + i) > *(x + temp)) temp = i;         i++;     }     return temp; } int getInfo(int *a, int max) {     int i = 0;     while (cin >> *a)     {         a++;         i++;         if (i == max) break;     }     return i; } int total (const int *a, int len) {     int sum = 0;     while (len--) sum +=*a;     return sum; } void sort (int *x, int n) {     int j;     while (n--)     {         j = *findmax(x, n);         swap (*(x + j), *(x + n));     } } void swap(int &x,int &y){ int temp = x; x = y; y = temp; }```
Oh sorry! Line 76 is;
Code:

`return temp;`
• 02-21-2011
chameleons
You are supposed to return an integer pointer, not an int. According to my understanding of the meaning of this function, just return (x+temp).
• 02-21-2011
csharp100
I do not think that is it. It gives me the same error only now it says "const int* to int*" for the same line. The prototype for the function must be intact. If I remove the * in the function prototype the program works perfectly but unfortunately I have to use the *.
• 02-21-2011
iMalc
x+temp is correct except that it will also require a const_cast to remove the constness.

The method signature is a bit dubious though, due to the const in only one of the two places.
• 02-22-2011
csharp100
Thanks everyone! It is now working!