Why am i getting an error when i try to compile this?
May 15, 2013 at 7:08am UTC
Im making a small game and I having some problem compiling the board. what am I doing 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<iostream>
#include<string>
using namespace std;
int height = 8;
int width = 8;
int field[width][height];
void startsettings(){
for (int i = 0; i < width; i++){
for (int o = 0; o < heigt; o++){
field[i][o] = 0;
}
}
}
void print(){
for (int i = 0; i < width; i++){
cout << endl;
for (int o = 0; o < heigt; o++){
cout << field[i][o];
}
}
}
main(){
startsettings();
print();
}
May 15, 2013 at 7:10am UTC
check the spelling of heigt
May 15, 2013 at 7:11am UTC
int main not just main(line 26). In C++, the main function is supposed to have a return type of an integer.
Aceix.
May 15, 2013 at 7:15am UTC
okay so i updates th code but it wont let me compile it.
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
#include<iostream>
#include<string>
using namespace std;
int height = 8;
int width = 8;
int field[width][height];
void startsettings(){
for (int i = 0; i < width; i++){
for (int o = 0; o < height; o++){
field[i][o] = 0;
}
}
}
void print(){
for (int i = 0; i < width; i++){
cout << endl;
for (int o = 0; o < height; o++){
cout << field[i][o];
}
}
}
int main(){
startsettings();
print();
return 0;
}
May 15, 2013 at 7:22am UTC
Your field array cannot be declared with non-const values. Assuming that you--and not the program nor the user--manually set the values of width and height, simply append the "const" qualifier to the beginning:
1 2
const int height = 8;
const int width = 8;
These variables are now constant and their values may not be modified.
May 15, 2013 at 7:30am UTC
okay thanks for the help.
Topic archived. No new replies allowed.