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.
Oh sorry! Line 76 is;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; }
Code:return temp;



LinkBack URL
About LinkBacks


