I am new to programming and kind of stuck on this assignment.
This is the code that I wrote so far:
#include <iostream>
using namespace std;
int Feld [11][11];
int main()
{
for (int Reihe = 0; Reihe <= 10; Reihe++)
{
for (int Zeile = 0; Zeile <= 10; Zeile++)
{
int Feld1[Reihe][Zeile] = Reihe * Zeile;
}
}
return 0;
}
and this results in the following error message:
tobias@Lonestar:~/c++$ g++ nl.cpp -Wall
nl.cpp: In function ‘int main()’:
nl.cpp:11:37: error: variable-sized object ‘Feld’ may not be initialized
nl.cpp:11:8: warning: unused variable ‘Feld’ [-Wunused-variable]
At the end of the day, I tried to work around that and declared the array in the following way:
const int AR = 11;
const int AZ = 11;
int Feld [AR][AZ];
for (int Zeile = 0; Zeile <= 10; Zeile++)
{
int Feld1[Reihe][Zeile] = Reihe * Zeile; // This declares a new array, hence Feld isn't used (it should emit an error because Reihe and Zeile are not const)
}
There was indeed a typo, like I said, I was messing around with the code for a while, but now that I have changed it, I still get the same error message.
This is how the code looks like right now and afterwards I post the error message:
int Feld [11][11];
int main()
{
for (int Reihe = 0; Reihe < 11; Reihe++)
{
for (int Zeile = 0; Zeile < 11; Zeile++)
{
int Feld[Reihe][Zeile] = Reihe * Zeile;
}
}
nl.cpp: In function ‘int main()’:
nl.cpp:11:37: error: variable-sized object ‘Feld’ may not be initialized
nl.cpp:11:8: warning: unused variable ‘Feld’ [-Wunused-variable]