My main function asks the user to enter a number then it calls this function using that number.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int fact(constint x)
{
double * table = newdouble[x];
table[0] = 1;
cout << "\n0! = 1\n";
for (int i = 1; i <= x; i++)
{
table[i] = i * table[i-1];
cout << i << "! = " << table[i] << "\n";
}
cout << "\n";
delete [] table;
return 0;
}
I ran the program without line 13 a few times and everything worked great. But then I remembered that when you use new you should match it with delete. Once I added line 13 I get an error: Debug Error! HEAP CORRUPTION DETECTED!
If anyone knows what the problem is I would really appreciate it.