I'm looking to show the amounts stored in the array that i saved using a pointer, but i am only getting back the dresses when i use my .show function. i could use some direction on what i should fix
# include <iostream>
using namespace std;
//moviegoers class
class movieGrs
{
private: int students, *location;
public:
void selectSort(int[],int);
void getStudents();
void makeLocation();
void loadArray(){cin>>location[students];}
int takeStudents(){return students;}
void show();
};
void movieGrs::show()
{ for(int x =0; x < students; x++)
cout << location[x] << " " << endl;
}
void movieGrs::getStudents() {cin >> students;}
void movieGrs::makeLocation(){location = new int[students];}
cout << "Please enter the amount of student that have been survayed for the last month" << endl << endl;
stats.getStudents();
stats.makeLocation();
for(int index = 0; index < stats.takeStudents(); index++)
{
cout << "Please enter the amount of movies seen by student " << index +1 << endl;
stats.loadArray();
}
I did not look through all your code but it is obvious that this function
void loadArray(){cin>>location[students];}
is invalid. You are trying to enter one element of your array outside allocated memory. You shall use a loop to enter a value for every elemnt of the array.