# Text box of points / Textkasten, bestehend aus Punkten

**URL:** <https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [April 13, 2020, 10:34am UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754 "2020-04-13T10:34:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gurki](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@gurki](https://discourse.processing.org/u/gurki)\
**Post date:** [April 13, 2020, 10:34am UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/1 "2020-04-13T10:34:58Z")

</div>

The next task is this one (also in german):

Schreiben Sie eine Funktion kreuz() mit vier den Parametern: hoehe, breite, zeile, spalte.  
Ihre Funktion sollte einen (Text-)Kasten der entsprechenden Höhe und Breite zeichnen, bestehend aus   
Punkten. Die angegebene Zeile sollte mit #-Zeichen ausgefüllt sein, die angegebene Spalte ebenfalls.  
Testen Sie Ihre Funktion mit folgendem Code:  
(verwenden Sie keine globalen Variablen!)  
void setup() {  
kreuz(5, 5, 2, 2);  
println();  
kreuz(6, 6, 0, 0);  
println();  
kreuz(4, 4, 3, 1);  
}  
Sie sollten folgenden Output sehen:

–  
If I print the code it should come this:

…#…  
…#…

##### 

…#…  
…#…

##### 

#…  
#…  
#…  
#…  
#…

.#…  
.#…  
.#…

#### 

* * *

Now I took the code from the other task and tried it a little bit but I dont know if I need one more loop or more If clauses.  
Could you say me what I should try then I will write my next code.

I tried it with this code but it is wrong

```auto
void kreuz(int h, int b, int z, int s)
{
  for (int zeile = 0; zeile < b; zeile++)
  {
    for (int spalte = 0; spalte < h; spalte++)
    {
      if (spalte < z)

      {
        print("#");
      } else
      {
        print(".");
      }
    }

    println();
  }
}

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 13, 2020, 4:11pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/2 "2020-04-13T16:11:59Z")

</div>

> [@gurki](#):
>
> I tried it with this code but it is wrong

What were you expecting to happen, and what specifically happens instead?

---

<div class="post-metadata">

**Author:** ![gurki](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@gurki](https://discourse.processing.org/u/gurki)\
**Post date:** [April 13, 2020, 4:25pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/3 "2020-04-13T16:25:47Z")

</div>

Hey Jeremy,

unfortunately it show me the wrong pattern of code in the console.

normally it should come this as an result:

```auto
…#…
…#…
#####
…#…
…#…

#…
#…
#…
#…
#…

.#…
.#…
.#…

```

I dont know how exactly i must switch the if causes. Do I need more else if variatens?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 13, 2020, 4:34pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/4 "2020-04-13T16:34:08Z")

</div>

> [@gurki](#):
>
> normally it should come this as an result:

Are you saying that this is what you **should** get, or what you **do** get?

If we look at the specific difference between _should_ and _do_, there will be a clue there for what to change.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 13, 2020, 5:06pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/5 "2020-04-13T17:06:44Z")

</div>

> [@gurki](#):
>
> Ihre Funktion sollte einen (Text-)Kasten der entsprechenden Höhe und Breite zeichnen, bestehend aus  
> Punkten.

Please do this first. How is the code for this?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 13, 2020, 5:08pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/7 "2020-04-13T17:08:53Z")

</div>

No

It is not

Chrisir

---

<div class="post-metadata">

**Author:** ![gurki](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@gurki](https://discourse.processing.org/u/gurki)\
**Post date:** [April 13, 2020, 5:28pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/8 "2020-04-13T17:28:32Z")

</div>

![Bild](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/cb246118341d48615f21b8beecd4b0cb77779bd1.png)

Hey Guys this is the output what my professor wants.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 13, 2020, 5:41pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/9 "2020-04-13T17:41:37Z")

</div>

Read my advice above and show your attempt

---

<div class="post-metadata">

**Author:** ![gurki](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@gurki](https://discourse.processing.org/u/gurki)\
**Post date:** [April 13, 2020, 6:02pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/10 "2020-04-13T18:02:19Z")

</div>

```auto
void setup() {
  kreuz(5, 5, 2, 2);
  println();
  kreuz(6, 6, 0, 0);
  println();
  kreuz(4, 4, 3, 1);
}

void kreuz(int h, int b, int z, int s)
{
  for (int zeile = 0; zeile < b; zeile++)
  {
    for (int spalte = 0; spalte < h; spalte++)
    {
      {

        if (spalte < z +1 && spalte > z - 1 )

        {
          print("#");
        } else if (zeile < s +1 && spalte > z-1)
        {
          print("#");
        }
        else
        {
          print(".");
        }
      }
    }
  
    println();
  }
}

```

Now this is the code which i tried.  
I expanded it with an else if cause. Unfortunately I couldn solve this problem.

Do I need more else if causes or are these 2 enough?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 13, 2020, 6:04pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/11 "2020-04-13T18:04:13Z")

</div>

This seems to be more guess work here

Why not do only . for one?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 13, 2020, 6:06pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/12 "2020-04-13T18:06:17Z")

</div>

> [@gurki](#):
>
> Die angegebene Zeile sollte mit #-Zeichen ausgefüllt sein, die angegebene Spalte ebenfalls.

When you filled the rectangle, continue with this.

This is an if clause with 2 conditions connected with ||

see reference

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 13, 2020, 6:07pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/13 "2020-04-13T18:07:18Z")

</div>

But your approach is good

Just use ==

---

<div class="post-metadata">

**Author:** ![gurki](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@gurki](https://discourse.processing.org/u/gurki)\
**Post date:** [April 13, 2020, 6:12pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/14 "2020-04-13T18:12:03Z")

</div>

```auto
void setup() {
  kreuz(5, 5, 2, 2);
  println();
  kreuz(6, 6, 0, 0);
  println();
  kreuz(4, 4, 3, 1);
}

void kreuz(int h, int b, int z, int s)
{
  for (int zeile = 0; zeile < b; zeile++)
  {
    for (int spalte = 0; spalte < h; spalte++)
    {
      {

        if (spalte < z +1 && spalte > z - 1 || zeile == s +1 && spalte == z || zeile == z)

        {
          print("#");
        } 
        else
        {
          print(".");
        }
      }
    }
  
    println();
  }
}

```

Now I understand mostly everything.  
The last pattern in the code is wrong.  
Could you give me a hint.  
I think I will finish it then.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 13, 2020, 6:16pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/15 "2020-04-13T18:16:34Z")

</div>

> [@gurki](#):
>
> Die angegebene Zeile sollte mit #-Zeichen ausgefüllt sein, die angegebene Spalte ebenfalls.

Just follow this sentence.

Your code is good except for the if clause

if ( zeile == z || spalte == s)

Weißt du warum?

Chrisir

---

<div class="post-metadata">

**Author:** ![gurki](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@gurki](https://discourse.processing.org/u/gurki)\
**Post date:** [April 13, 2020, 6:19pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/16 "2020-04-13T18:19:23Z")

</div>

```auto
zeile == z || spalte == z - 3 

```

Ja die letzte bedingung ist falsch aber ich komme nicht darauf.

#…#  
#…#  
#…#

#### 

Das kommt raus bei der Konsole

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 13, 2020, 6:20pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/17 "2020-04-13T18:20:13Z")

</div>

> [@Chrisir](#):
>
> if ( zeile == z || spalte == s)

??

Das ist doch die Lösung!!!

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 13, 2020, 6:31pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/18 "2020-04-13T18:31:05Z")

</div>

Vielleicht hast du b und h verwechselt in der for Schleife?

---

<div class="post-metadata">

**Author:** ![gurki](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@gurki](https://discourse.processing.org/u/gurki)\
**Post date:** [April 13, 2020, 6:31pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/19 "2020-04-13T18:31:27Z")

</div>

```auto
void setup() {
  kreuz(5, 5, 2, 2);
  println();
  kreuz(6, 6, 0, 0);
  println();
  kreuz(4, 4, 3, 1);
}

void kreuz(int h, int b, int z, int s)
{
  for (int zeile = 0; zeile < b; zeile++)
  {
    for (int spalte = 0; spalte < h; spalte++)
    {
      {

        if (spalte < z +1 && spalte > z || zeile == s +2 && spalte == z || zeile == z || spalte == s )

        {
          print("#");
        } 
        else
        {
          print(".");
        }
      }
    }
  
    println();
  }
}

```

Now I have the solution.  
This task was one of the hardest tasks in the exams.

Thank you all.  
I think I will start with the next task in the next hour.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 13, 2020, 6:38pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/20 "2020-04-13T18:38:04Z")

</div>

> [@Chrisir](#):
>
> Vielleicht hast du b und h verwechselt in der for Schleife?

Bitte teste es mal eben mit einer größeren Breite beim Aufruf in setup.

---

<div class="post-metadata">

**Author:** ![gurki](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@gurki](https://discourse.processing.org/u/gurki)\
**Post date:** [April 13, 2020, 6:43pm UTC](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754/21 "2020-04-13T18:43:21Z")

</div>

Hey Chris,

nee das passt so.  
Der Code passt.

[Next page](https://discourse.processing.org/t/text-box-of-points-textkasten-bestehend-aus-punkten/19754.md?page=2)
