I have a program that is creating random numbers...at least this is the best randomization I've seen out of any program (I've tried a lot of randomizing number algorithms and most of them aren't very effective). This program works perfectly fine unless I manipulate this one array of integers. The name of it is
" int num_t [ ] . Whenever I put the number 50, 100, 140, 150, 15 it gives me a memory referrencing error when I run the .exe. Whenever I put the number 160, 165 it doesn't display anything but no errors occurr when running the program. Whenever I put the numbers 200, 300, 170, 190, 400, 499, 500 it runs just as it should. Here is the code for the program...I have no idea why this is happening.
Code:
#include <iostream>
#include <time.h>
#include <conio.c>
#include <windows.h>
using namespace std;
void store();
void display();
int num_t[170]; /* with 170 being in there the program runs
fine, but whenever I put in certain numbers it
messes up as I explained */
int x = 0, y = 0, z = 0;
int main()
{
bool ACTIVE = true;
time_t hold_t[50];
hold_t[x] = time(NULL);
while(ACTIVE)
{
num_t[y] = hold_t[x];
store();
x++;
y++;
if(x > sizeof(hold_t))
{
ACTIVE = false;
}
}
display();
getch();
return 0;
}
void store()
{
num_t[z] = num_t[y];
z++;
}
void display()
{
z = 0;
for(int pass = 0; pass < 51; pass++)
{
system("CLS");
cout << num_t[z];
Sleep(500);
z++;
}
}
I've tried chaing around the values for hold_t and pass, but I narrowed the error down to when I change the value for num_t. I guess all in all it doesn't really matter, except that my curiousity has the best of me. I have absolutely no idea why it's doing this.