Apologies for any formatting errors this is my first post. I am not sure why this program will not work in Xcode. I receive an EXC_BAD_ACCESS error whenever i attempt to run it.
#include <iostream>
using namespace std;
int main ()
{
int MAX = 6;
int Arr[6] = {10, 8, 14, 16, 18, 37};
int *Arrptr[6];
//Here i have created two arrays, the original and one for pointers
int i;
int g;
int k;
//Here i increment through the arrays to find the highest value in the original array
//once the highest value is found it assigns the value's address to a pointer in the second array.
for ( i = 0; i < MAX ; i++)
{
*Arrptr[i] = 0;
for (g = 0; g < MAX; g++)
{
if (*Arrptr[i] > Arr[g])
{
Arrptr[i] = &Arr[g];
}
}
}
// Here i display the values in descending order by dereferincing the pointers in the pointer array.
cout << "Today's sales is descending order are!" << endl;
for (k = 0; k < MAX; k++ )
{
cout << *Arrptr[k] <<endl;
}
return 0;
}
Here is there original assignment: There is a store to sale laptops. From Monday to Saturday, here are numbers of laptops they sold for each day: 10 8 14 16 18 37 The store manager wants you to write a program that display the day sales in descending order, as well as in their original order.
Requirements: Please define two arrays in your program Arr: an array of integers to hold the day sales in original order; PtrArr: an array of pointers that can be used to display the contents of Arr in descending order, without sorting Arr
Thank you in advance for any help. Any feedback is appreciated.