HELP PLZ

i begin to make a tic tac toe, but, every time i execute then crash
what is wrong ?

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
#include <windows.h>
#include <iostream>
#include <string>

using namespace std;

//Global Vars
string line1[3] = {" ", " ", " "};
string line2[3] = {" ", " ", " "};
string line3[3] = {" ", " ", " "};

//Funçtions
void tabela(){
cout << endl;
cout << "   | " << line1[1] << " | " << line1[2] << " | " << line1[3] << " |" << endl;  //first line

cout << "   | " << line2[1] << " | " << line2[2] << " | " << line2[3] << " |" << endl;  //second line

cout << "   | " << line3[1] << " | " << line3[2] << " | " << line3[3] << " |" << endl;  //third line

}

main() {

    tabela();
    cout << "h6110 w0r1d" << endl;

    }
Your main function doesn't have a type. It should be of the type integer. It also misses a return value. A return value isn't necessary, but it is recommanded. The compiler will assume the return value is 0.

I would change your main function like this:

1
2
3
4
5
6
7
int main() {
    tabela();
    cout << "h6110 w0r1d" << endl;
    //The next line is to make sure the program doesn't exit within the second it opens
    cin.get();
    return 0;
}


But most likely the biggest problem is your array.

A C++ array starts at 0. So you define an array of strings with 3 elements. These elements would then be element 0, 1 and 2. You are using elements 1, 2 and 3. But element 3 isn't in the array, so it's a undefined part of the array. You need to correct the tabela function into this:

1
2
3
4
5
6
7
8
9
void tabela(){
cout << endl;
cout << "   | " << line1[0] << " | " << line1[1] << " | " << line1[2] << " |" << endl;  //first line

cout << "   | " << line2[0] << " | " << line2[1] << " | " << line2[2] << " |" << endl;  //second line

cout << "   | " << line3[0] << " | " << line3[1] << " | " << line3[2] << " |" << endl;  //third line

}


You can read about arrays on the array page in the tutorial on this site.
Last edited on
Topic archived. No new replies allowed.