Also habe ich versucht, ein leeres Quadrat innerhalb eines Rasters zu zeichnen. Ich habe das Gitter ursprünglich mit Zeichen von "*" unter Verwendung eines 2d-Arrays mit Breite 10 und Höhe 5 erstellt. Wenn ich jeden Array-Wert von bestimmten gegebenen Koordinaten ändere, zeichne ich das Quadrat von den Koordinaten, die die obere linke Ecke des Quadrats sind. Das Problem ist, wenn ich es ausgedruckt habe kommt nur die Hälfte raus.Hollow Square im Raster
Fehle ich eine Bedingung oder zu viele Bedingungen beim Umschreiben von Teilen des Grid-Arrays? Danke für die Hilfe.
int main(){
char grid[5][10];//initialize array that will be row and column
for(int i=0;i<5;i++){
for(int j=0;j<10;j++){
grid[i][j]= '*';
}//for
}//for loop to fill grid with asterisk
cout << "GRID" << endl << endl;
for(int i=0;i<5;i++){
for(int j=0;j<10;j++){
cout << grid[i][j] ;
}//for
cout << endl;
}//for loop to print grid no shapes inside
cout << endl << endl;
int x = 2;
int y = 3;
int size = 3;
char c = 'o';
//will have a condition here to check if it can fit inside the
//grid but this is just to test it will be a member function.
for(int n=x-1;n<x+size-1; n++){
for(int p=y-1;p<y+size-1; p++){
if (n == x-1 || n==x+size-1 || p == y-1 || p== y+size-1){
grid[n][p] = c;
}
else
grid[n][p] = '*';
}//for
}//for loop to rewrite specific array coordinates with new c
cout << "Shape inside grid." << endl;
for(int n=0;n<5;n++){
for(int p=0;p<10;p++){
cout << grid[n][p];
}//for
cout << endl;
}//for loop to print new grid
return 0;
}
/*
This is my output:
**********
**ooo*****
**o*******
**o*******
**********
This is what I need:
**********
**ooo*****
**o*o*****
**ooo*****
**********
*/
Sorry, ich hatte die richtige Idee Ich glaube, ich nur falsch gezählt. Vielen Dank für deine Hilfe. – pandalot