Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Loop(triangle-drawer)
    text
    copied!<p>i cant get my program to work, i tried it already with markers (goto). but i cant get it to work. I also tried to improve the loop but it ends with an infinite loop. Thanks for Help!</p> <pre><code>#include &lt;iostream&gt; //includes using namespace std; int makedreieck(int länge) // function for drawing a triangle { int rows=0; //rows int draw=0; //drawed while(draw &lt;= länge) { draw++; cout &lt;&lt; "*"; if(draw == länge-1) { rows++; draw = länge-rows; cout &lt;&lt; endl; } if(draw == 1) { getchar(); return 0; } } } int main(char argument) { int dreieck; cin &gt;&gt; dreieck; makedreieck(dreieck); getchar(); return 0; } </code></pre> <p>finally got all working... if anyone needs the code:</p> <pre><code>#include &lt;iostream&gt; #include &lt;time.h&gt; #include &lt;windows.h&gt; #include &lt;tchar.h&gt; using namespace std; int createtriangle(int length, bool custom, char symbol) { clock_t start, finish; length++; int OK=0; int OK_ABORT; int TRIANGLE_NOT_ALLOWED; enum returnvalues{OK, OK_ABORT, TRIANGLE_NOT_ALLOWED}; if(length&lt;=0) { cerr &lt;&lt; "Dreieck mit einer Laenge von " &lt;&lt; length-1 &lt;&lt;" unerlaubt."; return TRIANGLE_NOT_ALLOWED; } if(length&gt;81) { cout &lt;&lt; "Es wurde eine ueber 80 Sternchen lange Treppe entdeckt." &lt;&lt; endl &lt;&lt; "Es wird empfohlen die Operation abzubrechen"&lt;&lt; endl &lt;&lt; "1: abbrechen 2: weiter"&lt;&lt;endl&lt;&lt;"Auswahl: "; int sel; cin &gt;&gt; sel; getchar(); if(sel&gt;2) { cout &lt;&lt; "Es gibt die Auswahl: "&lt;&lt;sel&lt;&lt;" nicht."; } system("cls"); switch(sel) { case 1: return OK_ABORT; break; case 2: break; } } int rows=0; int draw=0; start = clock(); while(draw &lt;= length) { draw++; if(rows&gt;=1&amp;&amp;custom==false) { cout &lt;&lt; "*"; } if(rows&gt;=1&amp;&amp;custom==true) { cout &lt;&lt; symbol; } if(draw == length) { if(rows&gt;=1) { cout &lt;&lt; endl; } rows++; draw = length-rows; } if(rows == length) { finish=clock(); if(custom==false) { cout &lt;&lt; "Es wurde eine "&lt;&lt;length-1&lt;&lt;" Sternchen lange Treppe gebaut."&lt;&lt;endl; } else if(custom==true) { cout &lt;&lt; "Es wurde eine "&lt;&lt;length-1&lt;&lt;" "&lt;&lt;symbol&lt;&lt;" lange Treppe gebaut."&lt;&lt;endl; } cout &lt;&lt; "Es wurden "&lt;&lt; static_cast&lt;double&gt;( finish - start ) /CLOCKS_PER_SEC&lt;&lt; " Sekunden gebraucht."; return OK; } } return OK; } int main() { START: system("cls"); int dreieck; char time[9]; cout &lt;&lt; "Wie gross soll die Treppe sein?: "; cin &gt;&gt; dreieck; system("cls"); cout &lt;&lt; "Soll ein custom symbol verwendet werden?"&lt;&lt;endl&lt;&lt;"Ja:1 Nein:2"&lt;&lt;endl&lt;&lt;"Auswahl: "; int menu2; cin &gt;&gt; menu2; system("cls"); bool customtrue; char symbolcustom; if(menu2&gt;2) { cout &lt;&lt; "Die Auswahl: " &lt;&lt; menu2 &lt;&lt; " ist nicht verfügbar"; getchar(); goto START; } switch(menu2) { case 1: customtrue = true; cout &lt;&lt; "Symbol angeben(1Char max): "; cin &gt;&gt; symbolcustom; break; case 2: customtrue = false; break; } system("cls"); createtriangle(dreieck,customtrue,symbolcustom); getchar(); getchar(); menumark: system("cls"); cout &lt;&lt; "Soll erneut eine Treppe gebaut werden?"&lt;&lt;endl&lt;&lt;"1: Ja 2: Nein"&lt;&lt;endl&lt;&lt;"Auswahl: "; int menu; cin &gt;&gt; menu; if(menu&gt;2) { cout &lt;&lt;"Es gibt keine "&lt;&lt;menu&lt;&lt;" Auswahl."; getchar(); goto menumark; } switch(menu) { case 1: goto START; break; case 2: exit(0); break; } return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload