In geschachtelter for-Schleife mit Arrays zählen

SNOOK99

Mitglied
Hallo!

Zugegeben mein Titel ist etwas irreführend. Das Problem ist (warscheinlich) recht einfach zu lösen, blos weis ich nich wie ;)
Ich will ein Spielfeld mit 8 x 8 Fledern erstellen und mit ABCD.... waagerecht und Senkrecht mit 1..8 definierten.
Warum gibt er mir die Zahlen 1...8 nicht linksbündig (vor den Feldern) und passend zu den Feldern aus?

Code:
      #include <iostream>
      #include <conio>
      using namespace std;
      
      
      char feld[7][7];
      
      void init(void)
      {
       for (int i=0;i<=7;i++)
       {
        for (int j=0;j<=7;j++)
        {
         feld[i][j] = '0';
        }
       }
      }
      
      void prt(void)
      {
       cout << "Spielfeld:" << endl << endl;
       cout << "ABCDEFGH" << endl;
      
       for (int i=0;i<=7;i++)
       {
        cout << i+1 << " ";
        for (int j=0;j<=7;j++)
        {
      
      	  if (j % 8 == 0)
      	   cout << endl;
      	  cout << feld[i][j];
        }
      }
       cout << endl << endl;
      }
      
    int main(int argc, char* argv[])
      {
        init();
        prt();
      
      
      
      
       system("pause");
       return 0;
      }


Danke schonmal für euere Hilfe!
 
moin


Hier mal meine geänderte Version:
Code:
void prt(void)
{
	cout << "Spielfeld:" << endl << endl;
	cout << "ABCDEFGH" << endl;

	for (int i=0;i<=7;i++)
	{
		cout << i+1 << " ";
		for (int j=0;j<=7;j++)
		{
			cout << feld[i][j];
		}
		cout << endl;
	}
	cout << endl << endl;
}

Wenn das nciht ist was du willst, poste mal ein Beispiel.


mfg
umbrasaxum
 
moin


Dann hier nochmal:
Code:
void prt(void)
{
	cout << "Spielfeld:" << endl << endl;
	cout << "  ABCDEFGH" << endl << endl;

	for (int i=0;i<=7;i++)
	{
		cout << i+1 << " ";
		for (int j=0;j<=7;j++)
		{
			cout << feld[i][j];
		}
		cout << endl;
	}
	cout << endl << endl;
}
Da hätttest du aber auch selber drauf kommen können.


mfg
umbrasaxum
 
moin


Gern geschehen.
Aber setz den Threadstatus doch noch schnell auf "Erledigt", der Ordnung halber.


mfg
umbrasaxum
 
Zurück