So i need help figurin out where my segmentation fault is comin from. Im not even close to finishing this program but i was just testing my progress so far to make sure that it was taking values correctly, but sometimes the program doesnt stop when its supposed to and when it does i get a segmentation fault at the end, even if it works the way i want it to.
heres the code:
#include<iostream>
using namespace std;
class Heapsort
{
private:
int mylist[];
int mysize;
public:
void get_size();
bool empty();
void sort();
void fill_array();
void print(int);
};
void Heapsort::get_size()
{
cout <<endl<<"Please enter the size of the array you want to sort: ";
cin >> mysize;
int mylist[mysize];
}
void Heapsort::fill_array()
{
int i;
int num;
for (i=0; i < mysize; i++){
cout << "Enter a number 1-100: ";
cin >> num;
if ((num < 1)||(num > 100)){
cout << "\n\nEnter a correct number please.\n\n";
i = i - 1;
} else {
mylist[i] = num;
}
}
}
int main()
{
Heapsort heap;
heap.get_size();
cout << endl << endl;
heap.fill_array();
cout << endl << endl;
return (0);
}