Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using your source code &hellip;</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>the first few compilation errors with g++, &hellip;</p> <pre> [d:\dev\test] > <i>gnuc foo.cpp</i> foo.cpp:3:1: error: stray '\344' in program foo.cpp:7:5: error: stray '\344' in program foo.cpp:11:9: error: stray '\344' in program foo.cpp:14:13: error: stray '\344' in program foo.cpp:3:23: error: expected ',' or '...' before 'nge' foo.cpp: In function 'int makedreieck(int)': foo.cpp:7:21: error: expected ')' before 'nge' foo.cpp:7:21: error: 'nge' was not declared in this scope foo.cpp:7:24: error: expected ';' before ')' token foo.cpp:5:9: warning: unused variable 'rows' [-Wunused-variable] foo.cpp:32:1: error: expected '}' at end of input foo.cpp:32:1: warning: no return statement in function returning non-void [-Wreturn-type] [d:\dev\test] > _ </pre> <p>are due to the MingW g++ compiler for Windows not conforming to the C++ standard about the character set accepted in identifiers. The particular character numbers reported are a bit odd because the source code was saved as Windows ANSI Western, but g++ errs out also with the source code as UTF-8. As of 2013 <em>few compilers are</em> conforming wrt. the source character set.</p> <p>The only safe characters are A through Z, underscore, and the digits 0 through 9.</p> <p>In practice this means: <strong>write your source code in English</strong>, the <em>lingua franca</em> of software development, and then it can be maintained by others and compiled by other compilers.</p> <p>After fixing that I get the following compilation errors:</p> <pre> [d:\dev\test] > <i>gnuc foo.cpp</i> foo.cpp: In function 'int makedreieck(int)': foo.cpp:19:21: error: 'getchar' was not declared in this scope foo.cpp: At global scope: foo.cpp:25:5: warning: first argument of 'int main(char)' should be 'int' [-Wmain] foo.cpp:25:5: warning: 'int main(char)' takes only zero or two arguments [-Wmain] foo.cpp: In function 'int main(char)': foo.cpp:30:13: error: 'getchar' was not declared in this scope foo.cpp: In function 'int makedreieck(int)': foo.cpp:23:1: warning: control reaches end of non-void function [-Wreturn-type] [d:\dev\test] > _ </pre> <p>The errors here are due to not including the header <code>&lt;stdio.h&gt;</code> that declares the <code>getchar</code> function.</p> <p>After fixing that there are no more errors reported.</p> <p>However, the warnings are serious:</p> <pre> [d:\dev\test] > <i>gnuc foo.cpp</i> foo.cpp:27:5: warning: first argument of 'int main(char)' should be 'int' [-Wmain foo.cpp:27:5: warning: 'int main(char)' takes only zero or two arguments [-Wmain] foo.cpp: In function 'int makedreieck(int)': foo.cpp:25:1: warning: control reaches end of non-void function [-Wreturn-type] [d:\dev\test] > _ </pre> <p>The non-standard <code>main</code> signature means that even after including the required header, this is <em>not valid C++</em>.</p> <p>Just remove the (unused) formal argument.</p> <p>Then the code compiles, with only one very serious warning remaining:</p> <pre> [d:\dev\test] > <i>gnuc foo.cpp</i> foo.cpp: In function 'int makedreieck(int)': foo.cpp:25:1: warning: control reaches end of non-void function [-Wreturn-type] [d:\dev\test] > _ </pre> <p>Which absolutely needs to be fixed!</p> <p>Summing up:</p> <ul> <li><p>Change the code to not use non-English letters in identifiers. Those national characters are OK wrt. the C++ standard, but few compilers support them. In particular g++ does not.</p></li> <li><p>Include all required headers.</p></li> <li><p>Use a standard-conforming signature for <code>main</code>.</p></li> </ul> <p>And remember to fix the missing <code>return</code> statement thing.</p> <p><em>Then</em> you can start debugging!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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