<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problemfall: Tabelle erzeugen]]></title><description><![CDATA[<p>Erst ein mal ein freundliches Hallo <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Es geht um folgende Thematik / folgendes Problem:</p>
<p>Ich soll eine Tabelle erzeugen (in einer einfachen Console), wobei der User zwei Werte eingibt. Daraus ergeben sich dann die Anzahl der Zeilen und Spalten.</p>
<p>Aussehen soll das Ganze so:</p>
<p>1 2 3<br />
_ _ _ _ _ _<br />
1 | 1 2 3 |<br />
2 | 2 4 6 |<br />
3 | 3 6 9 |<br />
4 | ......|</p>
<p>Ich hatte gerade schon mal mit Arrays rumprobiert und wollte dann entsprechend die Werte die eingegeben wurden an die Arrays übergeben. Hat aber noch nicht ganz so geklappt wie es sollte. Hat da noch jemand eine (bessere) Idee?=)</p>
<p>Wär für jede(n) Tipp / Vorschlag / Hilfe dankbar <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/244567/problemfall-tabelle-erzeugen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 19 Sep 2026 03:06:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/244567.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 02 Jul 2009 08:37:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problemfall: Tabelle erzeugen on Thu, 02 Jul 2009 08:37:49 GMT]]></title><description><![CDATA[<p>Erst ein mal ein freundliches Hallo <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Es geht um folgende Thematik / folgendes Problem:</p>
<p>Ich soll eine Tabelle erzeugen (in einer einfachen Console), wobei der User zwei Werte eingibt. Daraus ergeben sich dann die Anzahl der Zeilen und Spalten.</p>
<p>Aussehen soll das Ganze so:</p>
<p>1 2 3<br />
_ _ _ _ _ _<br />
1 | 1 2 3 |<br />
2 | 2 4 6 |<br />
3 | 3 6 9 |<br />
4 | ......|</p>
<p>Ich hatte gerade schon mal mit Arrays rumprobiert und wollte dann entsprechend die Werte die eingegeben wurden an die Arrays übergeben. Hat aber noch nicht ganz so geklappt wie es sollte. Hat da noch jemand eine (bessere) Idee?=)</p>
<p>Wär für jede(n) Tipp / Vorschlag / Hilfe dankbar <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735859</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735859</guid><dc:creator><![CDATA[bmth]]></dc:creator><pubDate>Thu, 02 Jul 2009 08:37:49 GMT</pubDate></item><item><title><![CDATA[Reply to Problemfall: Tabelle erzeugen on Thu, 02 Jul 2009 08:40:56 GMT]]></title><description><![CDATA[<p>Ein 2D Array bietet sich doch an.<br />
Warum zeighst du denn nicht mal deinen Versuch? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /> :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735861</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735861</guid><dc:creator><![CDATA[Jim Isaac Neutron]]></dc:creator><pubDate>Thu, 02 Jul 2009 08:40:56 GMT</pubDate></item><item><title><![CDATA[Reply to Problemfall: Tabelle erzeugen on Thu, 02 Jul 2009 08:53:10 GMT]]></title><description><![CDATA[<p>Hatte den gerade wieder verworfen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> Aber vielleicht sowas in der Richtung:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

void printarray (int arg[], int length) {
  for (int n=0; n&lt;length; n++)
    cout &lt;&lt; arg[n] &lt;&lt; &quot; &quot;;
  cout &lt;&lt; &quot;\n&quot;;
}

int main ()
{
  int firstarray[] = {5, 10, 15};
  int secondarray[] = {2, 4, 6, 8, 10};
  printarray (firstarray,3);
  printarray (secondarray,5);
  return 0;
}
</code></pre>
<p>Wobei ich da ja noch Werte vorgebe und das Drumherum noch ergänzt werden muss. Sprich die Striche, Eingabe des Users. Ich überlege gerade nur wie ich am besten dann die eingegebenen Werte übergeben kann -.-</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735868</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735868</guid><dc:creator><![CDATA[bmth]]></dc:creator><pubDate>Thu, 02 Jul 2009 08:53:10 GMT</pubDate></item><item><title><![CDATA[Reply to Problemfall: Tabelle erzeugen on Thu, 02 Jul 2009 09:31:27 GMT]]></title><description><![CDATA[<p>2Dimensionales Array:</p>
<pre><code class="language-cpp">int breite, hoehe;
cin &gt;&gt; breite;
cin &gt;&gt; hoehe;

int **matrix = new int[breite][hoehe];
//dann frag in irgendeiner schleife ab welche werte wo stehen

for( int h=0; h&lt;hoehe; ++h )
{
     for( int b=0; b&lt;breite; ++b )
           cout &lt;&lt; matrix[b][h] &lt;&lt; &quot; &quot;;
     cout &lt;&lt; endl;
}
</code></pre>
<p>sowas in der art. Gut möglich dass ich breite/hoehe verwechsle oder so <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735882</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735882</guid><dc:creator><![CDATA[Jim Isaac Neutron]]></dc:creator><pubDate>Thu, 02 Jul 2009 09:31:27 GMT</pubDate></item><item><title><![CDATA[Reply to Problemfall: Tabelle erzeugen on Mon, 06 Jul 2009 07:26:22 GMT]]></title><description><![CDATA[<p>Mh ich bekomme gerade noch zwei Fehlermeldungen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":/"
      alt="😕"
    /></p>
<p>error C2540: non-constant expression as array bound</p>
<p>&amp;</p>
<p>error C2440: 'initializing' : cannot convert from 'int (*)[1]' to 'int **'</p>
<p>Ich weiss gerade ehrlich gesagt nicht warum er mit den &quot;**&quot; Probleme hat:/ Kann mir da jemand helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737727</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737727</guid><dc:creator><![CDATA[bmth]]></dc:creator><pubDate>Mon, 06 Jul 2009 07:26:22 GMT</pubDate></item><item><title><![CDATA[Reply to Problemfall: Tabelle erzeugen on Mon, 06 Jul 2009 09:10:41 GMT]]></title><description><![CDATA[<p>Weils falsch ist:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39489.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-39489.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737770</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737770</guid><dc:creator><![CDATA[Jim Isaac Neutron]]></dc:creator><pubDate>Mon, 06 Jul 2009 09:10:41 GMT</pubDate></item><item><title><![CDATA[Reply to Problemfall: Tabelle erzeugen on Mon, 06 Jul 2009 09:21:01 GMT]]></title><description><![CDATA[<p>Einfacher ist es wohl 2 std::vector zu schachteln.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737780</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737780</guid><dc:creator><![CDATA[Blubberfisch]]></dc:creator><pubDate>Mon, 06 Jul 2009 09:21:01 GMT</pubDate></item><item><title><![CDATA[Reply to Problemfall: Tabelle erzeugen on Mon, 06 Jul 2009 09:45:40 GMT]]></title><description><![CDATA[<p>Also irgendwie tue ich mich da schwer...</p>
<p>Ich kriegs nicht hin so eine Ausgabe zu bekommen:</p>
<p>[cpp]<br />
1 2 3 4 ...<br />
_ _ _ _ _ ...<br />
1|1 2 3 4 ...<br />
2|2 4 6 8 ...<br />
3|3 6 9 12 ...<br />
4|4 8 12 16 ....<br />
.<br />
.<br />
.</p>
<p>Wie gesagt, Problem/Fall ist: Der user gibt 2 Werte ein (z.B. x, y) wobei er damit die Anzahl der Zeilen und Spalten eingibt (sprich bei Eingaben 1 und 1 = 1x1 Matrix usw.). Entsprechend soll diese Tabelle generiert werden. Aber auch mit dem Link von gerade komm ich irgendwie nicht weiter -.- Ich mach noch nicht so lange was mit C++ deswegen hoffe ich ihr könnt mir das noch genauer erklären, bin über jede Hilfe dankbar!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737797</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737797</guid><dc:creator><![CDATA[bmth]]></dc:creator><pubDate>Mon, 06 Jul 2009 09:45:40 GMT</pubDate></item><item><title><![CDATA[Reply to Problemfall: Tabelle erzeugen on Mon, 06 Jul 2009 10:14:57 GMT]]></title><description><![CDATA[<p>Meinst du sowas?</p>
<pre><code class="language-cpp">//////////////////////////////////////////////////////////////////////////
// main : Implementation file

#include &lt;string&gt;
#include &lt;sstream&gt;
#include &lt;iostream&gt;

void pause()
{
	std::cout &lt;&lt; &quot;PAUSE&quot; &lt;&lt; std::endl;

	std::cin.clear();
	std::cin.ignore(std::cin.rdbuf()-&gt;in_avail());
	std::cin.get();
}

std::size_t calcMaxSize(unsigned int x)
{
	std::ostringstream oss;
	oss &lt;&lt; x;

	return oss.str().length();
}

int main()
{
	unsigned int width;
	unsigned int height;

	std::cout &lt;&lt; &quot;Width:  &quot;;
	std::cin &gt;&gt; width;
	std::cout &lt;&lt; &quot;Height: &quot;;
	std::cin &gt;&gt; height;

	std::cout &lt;&lt; &quot;\n\n&quot;;

	std::size_t maxHeightSize = calcMaxSize(height);
	std::size_t maxPowSize = calcMaxSize(width * height);

	std::string heightGap(maxHeightSize, ' ');

	std::cout &lt;&lt; heightGap &lt;&lt; ' ';

	for(unsigned int w = 1; w &lt;= width; ++w)
	{
		std::cout.width(maxPowSize);
		std::cout &lt;&lt; w &lt;&lt; ' ';
	}

	std::cout &lt;&lt; &quot;\n\n&quot;;

	std::string line(maxHeightSize + 1 + maxPowSize * width + width, '-');
	std::cout &lt;&lt; line &lt;&lt; '\n';

	for(unsigned int h = 1; h &lt;= height; ++h)
	{
		std::cout.width(maxHeightSize);
		std::cout &lt;&lt; h &lt;&lt; '|';

		for(unsigned int w = 1; w &lt;= width; ++w)
		{
			std::cout.width(maxPowSize);
			std::cout &lt;&lt; (w * h) &lt;&lt; ' ';
		}

		std::cout &lt;&lt; '\n';
	}

	std::cout &lt;&lt; std::endl;

	pause();
	return 0;
}
</code></pre>
<p>Fehleingaben müsstest du noch selber abfangen. Vor allem auch Überläufe können dir hier einen Strich durch die Rechnung machen.<br />
Falls immer noch die Speicherung das Problem ist, dann arbeite am besten mit einem ein dimensionalen <code>std::vector</code> oder C Array. Die zweite Dimension darin kannst du durch einen Offset simulieren.</p>
<p>Pseudo C++ Code mässig:</p>
<pre><code class="language-cpp">unsigned int* array = new unsigned int[width * height];

// Zugriff auf Element [x][y]:
array[y * width + x] = x * y;
</code></pre>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737811</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737811</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Mon, 06 Jul 2009 10:14:57 GMT</pubDate></item><item><title><![CDATA[Reply to Problemfall: Tabelle erzeugen on Mon, 06 Jul 2009 10:23:27 GMT]]></title><description><![CDATA[<p>Wow, erst mal danke für die schnelle Antwort! Ja das sieht schon mal sehr sehr gut aus, ich werde dann mal versuchen die von dir angesprochenen Probleme abzufangen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737819</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737819</guid><dc:creator><![CDATA[bmth]]></dc:creator><pubDate>Mon, 06 Jul 2009 10:23:27 GMT</pubDate></item><item><title><![CDATA[Reply to Problemfall: Tabelle erzeugen on Tue, 07 Jul 2009 08:47:22 GMT]]></title><description><![CDATA[<p>Ok, soweit funktioniert es ja, jetzt gibt es noch zwei kleine Dinge die mcih ärgern:D</p>
<p>Einmal wäre es die Tatsache dass wenn ich an Werten z.B. 4 und 5 eingebe in der ersten Zeile nur bis zur 4 ausgegeben wird, statt die 5. Denn die fehlt dann noch in der obersten Zeile der Tabelle.</p>
<p>Und ich wollte fragen ob man bei meiner Abfrage bzgl. des einlesens/abfangen der Eingaben das Ganze noch modifizieren kann. Halt für den Fall dass man zweistellige Werte eingeben will (10 und 10 z.B.).</p>
<p>Ich poste mal den ganzen Code, ich denke das geht noch weil es ja nicht so viel ist.</p>
<pre><code class="language-cpp">////////////////////////////////////////////////////////////////////////// 
// main : Implementation file 
#include &quot;stdafx.h&quot;
#include &lt;string&gt; 
#include &lt;sstream&gt;
#include &lt;conio.h&gt;
#include &lt;iostream&gt; 

#define MAXCHARS 4

using namespace std;

void freezeProg() 
{ 

    cout &lt;&lt; &quot;freeeeezed, waiting for new Input =) (Prefer Enter;) &quot; &lt;&lt; std::endl; 

	// 
    cin.clear();

	// Hier wird geprüft mit welche Taste gedrückt wurde, in dem Fall
	// wird nur bei Enter reagiert :)
    cin.ignore(std::cin.rdbuf()-&gt;in_avail()); 
    cin.get(); 
} 

	// Berechnung der maximalen Größe des Strings
	size_t calcMaxSize(unsigned int x) 
	{ 
		ostringstream oss; 
		oss &lt;&lt; x; 

		return oss.str().length(); 
	} 

int main(void) { 

    //unsigned int height    = 0; 

    //unsigned int width     = 0; //strlen(tocheck); // tocheck undefined here..

    unsigned long int loop = 0;

    char c;

    do {

       cout &lt;&lt; &quot;Bitte geben Sie einen Wert fuer die Anzahl der Zeilen ein!:&quot; &lt;&lt; endl;

       c = _getch(); // Muss auf keine Eingabe warten, Taste ist bereits gedrückt 

    } while( !isdigit(c) );

    unsigned int width = (int) c-'0';

    do {

       cout &lt;&lt; &quot;Bitte geben Sie einen Wert fuer die Anzahl der Spalten ein!:&quot; &lt;&lt; endl;

       c = _getch(); // Muss auf keine Eingabe warten, Taste ist bereits gedrückt 

    } while( !isdigit(c) );

    unsigned int height = (int) c-'0';

    // Berechnung

    size_t maxHeightSize = calcMaxSize(height); 

    size_t maxWidthSize  = calcMaxSize(width * height); 

    string heightR(maxHeightSize, ' '); 

    cout &lt;&lt; heightR &lt;&lt; ' '; 

    // z = zeilen =&gt; width

    for(unsigned int z = 1; z &lt;= width; ++z) { 

        cout.width(maxWidthSize); 

        cout &lt;&lt; z &lt;&lt; ' '; 

    } 

    cout &lt;&lt; &quot;\n\n&quot;; 

    // Berechnung + Zeichen für obere Randmarkierung

    string line(maxHeightSize + 1 + maxWidthSize * width + width, '-'); 

    cout &lt;&lt; line &lt;&lt; '\n'; 

    // s = spalten =&gt; height

    for(unsigned int s = 1; s &lt;= width; ++s)  { 

        cout.width(maxHeightSize);

             // | Zeichen für die linke Randdarstellung

        cout &lt;&lt; s &lt;&lt; '|'; 

        for(unsigned int z = 1; z &lt;= height; ++z) { 

            cout.width(maxWidthSize); 

            cout &lt;&lt; (z * s) &lt;&lt; ' '; 

        } 

        cout &lt;&lt; '\n'; 

    } 

    // Erzeugt eine Leerzeile zwischen der Tabelle und der cout Angabe von freezeprog 

    cout &lt;&lt; endl; 

    freezeProg(); 

    return 0; 

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1738366</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1738366</guid><dc:creator><![CDATA[bmth]]></dc:creator><pubDate>Tue, 07 Jul 2009 08:47:22 GMT</pubDate></item><item><title><![CDATA[Reply to Problemfall: Tabelle erzeugen on Tue, 07 Jul 2009 08:59:11 GMT]]></title><description><![CDATA[<p>Nachtrag:</p>
<p>Das Anzeige Problem ist gelöst, bleibt nur noch das mit dem mehrere Zeichen einlesen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1738372</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1738372</guid><dc:creator><![CDATA[bmth]]></dc:creator><pubDate>Tue, 07 Jul 2009 08:59:11 GMT</pubDate></item></channel></rss>