crash upon execution

I have been working on this for practice to help my skills and i have run into a bit of a snag to where the exe crashes every time it runs. can anyone help my?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

main(int argc, char *argv[])
{
         stringstream t1q[50][9];
         stringstream t2q[40][20];
         {
         t1q[50][0] << "what is your opinion on ";
         t1q[50][1] << "do you like ";
         t1q[50][2] << "these are the best classes for you based off of you answers: ";
    
	     t1q[50][3] << "the use of melee weapons?";
  	     t1q[50][4] << "the use of ranged weapons?";
  	     t1q[50][5] << "the use of magic?";
  	     t1q[50][6] << "fighting for honor?";
  	     t1q[50][7] << "fighting for money?";
         t1q[50][8] << "fighting for the innocent?";
         }
		   //warrior questions
           t2q[40][1] << "";
		   t2q[40][2] << "";
		   t2q[40][3] << "";
		   t2q[40][4] << "";
		   t2q[40][5] << "";

		   //rogue questions
           t2q[40][6] << "";
		   t2q[40][7] << "";
		   t2q[40][8] << "";
		   t2q[40][9] << "";
		   t2q[40][10] << "";
		   
	       //mage questions
           t2q[40][11] << "";
		   t2q[40][12] << "";
		   t2q[40][13] << "";
		   t2q[40][14] << "";
		   t2q[40][15] << "";
           


int a[6], d, c, b;
for(c=0; c<3; c++)
	for(b=3; b<9; b++)
		cout << t1q[50][c];
		cout << t1q[50][b];
		cin>>a[b];
		switch(a[b])
        {
			case 1:
                 d = a[b];
                 cout << d;
			case 2:
			     d = a[b];
			     cout << d;
			case 3:
			     d = a[b];
			     cout << d;
			case 4:
			     d = a[b];
			     cout << d;
			case 5:
			     d = a[b];
			     cout << d;
                 }      
   
            
};
	
The main problem is that an array of size 50 has memory addresses 0 - 49. This will cause the same crash you have:
1
2
3
4
int arr[2];
arr[2] = 5;

// This array can only be accessed through arr[0] and arr[1] 


The section that starts at line 47 needs some help. I don't know if you don't have enough brackets. The big issue here is that cin >> a[b] is quick to cause a crash if b is greater than 5.

The general shape of main is not quite correct either:
1
2
3
4
5
6
int main()
{ 
  //stuff your program does

  return 0;
}

Last edited on
Topic archived. No new replies allowed.