When I start to debug the following code in Visual C++ and it runs in debug mode, it gives me this error: "Unhandled exception at 0x1027d51c(msvcr100d.dll) in st.exe:0xC0000005: Access violation reading location 0x00000009." The weird part is that the program starts to run, but shows me the error a little into it.
Here is the code:
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <time.h>
using namespace std;
int main () {
int a, b, c, d, e;
int junk;
srand(time(NULL));
char *scrpt[][2] = {
"What color is the sky?", "Blue",
"What is the shape of the moon?", "Circle",
"What is the coloer of an apple?", "Red",
"Which is longer, an inch or a meter?", "Meter",
"Do these questions make sense?", "Nope"
};
a = rand() % 10 + 1;
if (a == 2) a = 1;
if (a == 4) a = 3;
if (a == 6) a = 5;
if (a == 8) a = 7;
if (a == 10) a = 9;
b = rand() % 10 + 1;
do { b = rand() % 10 + 1;
} while(a == b);
if (b == 2) b = 1;
if (b == 4) b = 3;
if (b == 6) b = 5;
if (b == 8) b = 7;
if (b == 10) b = 9;
c = rand() % 10 + 1;
do { c = rand() % 10 + 1;
} while((a == c) || (b == c));
if (c == 2) c = 1;
if (c == 4) c = 3;
if (c == 6) c = 5;
if (c == 8) c = 7;
if (c == 10) c = 9;
d = rand() % 10 + 1;
do { d = rand() % 10 + 1;
} while((a == d) || (b == d) || (c == d));
if (d == 2) d = 1;
if (d == 4) d = 3;
if (d == 6) d = 5;
if (d == 8) d = 7;
if (d == 10) d = 9;
e = rand() % 10 + 1;
do { e = rand() % 10 + 1;
} while((a == e) || (b == e) || (c == e) || (d == e));
if (e == 2) e = 1;
if (e == 4) e = 3;
if (e == 6) e = 5;
if (e == 8) e = 7;
if (e == 10) e = 9;
cout << scrpt[a][0];
cout << "\n";
cout << "Press ENTER if you are ready to reveal c/v.\n";
cin >> junk;
cout << "\n";
cout << scrpt[a][1];
cout << "\n";
cout << "\n";
cout << scrpt[b][0];
cout << "\n";
cout << "Press ENTER if you are ready to reveal c/v.\n";
cin >> junk;
cout << "\n";
cout << scrpt[b][1];
cout << "\n";
cout << "\n";
cout << scrpt[c][0];
cout << "\n";
cout << "Press ENTER if you are ready to reveal c/v.\n";
cin >> junk;
cout << "\n";
cout << scrpt[c][1];
cout << "\n";
cout << "\n";
cout << scrpt[d][0];
cout << "\n";
cout << "Press ENTER if you are ready to reveal c/v.\n";
cin >> junk;
cout << "\n";
cout << scrpt[d][1];
cout << "\n";
cout << "\n";
cout << scrpt[e][0];
cout << "\n";
cout << "Press ENTER if you are ready to reveal c/v.\n";
cin >> junk;
cout << "\n";
cout << scrpt[e][1];
cout << "\n";
cout << "\n";
cout << "\n";
cout << "Well done!\n";
cin >> junk;
return 0;
}
Also the code failed debug.