Hi! First, I want to say that this is not any type of school assignment. I'm in the IT field and looking to work on learning C++. I've been following the book from: http://msdn.microsoft.com/en-us/beginner/cc305129.aspx and I'm now trying things on my own.
The program which the code below compiles will sometimes crash out at the beginning of its execution. I'm trying to put in any type of error catcher where the program will know that the program is about to crash, and it'll exit on its own behalf instead of crashing out by Windows Illegal Operation. I hope this makes sense.
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
//Initialize variables
int n = 0;
int z = 0;
int *i,j[10];
double *f,g[10];
float *k,l[21];
int *p,m[1];
int x;
// Associate pointers...
i=j;
f=g;
k=l;
p=m;
// "Splash" Screen
cout << "\nA just for fun program\n";
Sleep(1000);
//Start the real work here
for(x=1;x<350;x++)
{
cout << "\nAttempt #: " << x << '\n';
Sleep(10);
n = (rand()%375)+11;
cout << "Scanning to look cool: ";
z = i[n]+x;
cout << z;
if (!z)
{
cout << "Trying to catch an error here...but I'm not working \nExiting\n";
break;
}
cout << i[n]+x<< ' ' << f+x << ' ' << k+x <<'\n';
}
cout << "This looked cool...";
return 0;
}
I don't think "z" is my problem, but I just don't know enough to troubleshoot any further. Can anyone point me in the right direction? Thank you, -MT