I'm having trouble understanding what the problem is, but I'm trying extremely hard to understand pointers and I have the basic concept down.. I feel as though my knowledge of dynamically allocated pointers and pointers in general is not enough to understand the logic behind what I'm trying to do. The problem is that the donations array must be able to accept any number of donations. I've made it do just that, but there is also an array of pointers which must each point to the same element in the donations array. The program works if I assign int *arrPtr[100] for example, but it does not work if I try to dynamically allocate it to accept the same number of elements for donations entered by the user. Here it's the snippet, I hope it's enough to diagnose.
#include <iostream>
usingnamespace std;
//Function Prototypes
void arrSelectSort(int *[], int);
void showArray(constint [], int);
void showArrPtr(int *[], int);
int main()
{
int *donations; //Dynamically allocate the donations array.
int numDonations; //Holds the amount of donations the user wants to enter.
int *arrPtr;
//Get the number of individual donations the user wants to enter.
cout << "How many donations were made to the United Cause? : ";
cin >> numDonations;
//Ask the computer to allocate space to hold the number of donations made.
donations = newint[numDonations];
arrPtr = newint[numDonations];
//Get the amount of each donation.
cout << "Enter each donation below.\n";
for (int count = 0; count < numDonations; count++)
{
cout << "Employee " << (count+1) << ": ";
cin >> donations[count];
}
//Each element of arrPtr is a pointer to int. Make each
//element point to an element in the donations array.
for (int count = 0; count < numDonations; count++)
arrPtr[count] = &donations[count];
Line 35 is the specific line that is giving me a problem.