<?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[Rechner schreiben -&amp;gt; if problem]]></title><description><![CDATA[<p>Hallo zusammen<br />
bin neu hier und bin auch noch ein anfänger was c++ angeht.</p>
<p>habe so zum anfang einen kleinen rechner geschrieben, aber habe den ganze forum und google durchsucht, leider kein erfolg.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;
int main()
{
	int zahl1;
	int zahl2;
	char op[2];
	cout &lt;&lt;&quot;erste Zahl eingeben!&quot; &lt;&lt;  endl;
	cin &gt;&gt;zahl1;
	cout &lt;&lt;&quot;Operationszeichen eingeben! -&gt; +,-,*,/&quot; &lt;&lt;  endl;
	cin &gt;&gt;op[1];
	cout &lt;&lt;&quot;zweite Zahl eingeben!&quot; &lt;&lt;  endl;
	cin &gt;&gt;zahl2;
	if (op == &quot;+&quot;)
	{
		cout &lt;&lt; zahl1 + zahl2 &lt;&lt;  endl;
	}
	if (op == &quot;-&quot;)
	{
		cout &lt;&lt; zahl1 - zahl2 &lt;&lt;  endl;
	}
	if (op == &quot;*&quot;)
	{
		cout &lt;&lt; zahl1 * zahl2 &lt;&lt;  endl;
	}
	if (op == &quot;/&quot;)
	{
		cout &lt;&lt; zahl1 / zahl2 &lt;&lt;  endl;
	}
	return 0;
}
</code></pre>
<p>habe den rechner kompiliert und getestet, aber habe keine ausgabe bekommen nach dem if.</p>
<p>danke im voraus <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/248577/rechner-schreiben-gt-if-problem</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 23:46:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/248577.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 26 Aug 2009 17:12:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Rechner schreiben -&amp;gt; if problem on Wed, 26 Aug 2009 17:12:22 GMT]]></title><description><![CDATA[<p>Hallo zusammen<br />
bin neu hier und bin auch noch ein anfänger was c++ angeht.</p>
<p>habe so zum anfang einen kleinen rechner geschrieben, aber habe den ganze forum und google durchsucht, leider kein erfolg.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;
int main()
{
	int zahl1;
	int zahl2;
	char op[2];
	cout &lt;&lt;&quot;erste Zahl eingeben!&quot; &lt;&lt;  endl;
	cin &gt;&gt;zahl1;
	cout &lt;&lt;&quot;Operationszeichen eingeben! -&gt; +,-,*,/&quot; &lt;&lt;  endl;
	cin &gt;&gt;op[1];
	cout &lt;&lt;&quot;zweite Zahl eingeben!&quot; &lt;&lt;  endl;
	cin &gt;&gt;zahl2;
	if (op == &quot;+&quot;)
	{
		cout &lt;&lt; zahl1 + zahl2 &lt;&lt;  endl;
	}
	if (op == &quot;-&quot;)
	{
		cout &lt;&lt; zahl1 - zahl2 &lt;&lt;  endl;
	}
	if (op == &quot;*&quot;)
	{
		cout &lt;&lt; zahl1 * zahl2 &lt;&lt;  endl;
	}
	if (op == &quot;/&quot;)
	{
		cout &lt;&lt; zahl1 / zahl2 &lt;&lt;  endl;
	}
	return 0;
}
</code></pre>
<p>habe den rechner kompiliert und getestet, aber habe keine ausgabe bekommen nach dem if.</p>
<p>danke im voraus <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/1767175</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767175</guid><dc:creator><![CDATA[amMaster]]></dc:creator><pubDate>Wed, 26 Aug 2009 17:12:22 GMT</pubDate></item><item><title><![CDATA[Reply to Rechner schreiben -&amp;gt; if problem on Wed, 26 Aug 2009 17:16:58 GMT]]></title><description><![CDATA[<p>du machst zwei fatale fehler:<br />
1. char op[2] erzeugt platz für 2 chars. Du ließt den char in op[1] ein. Das erste zeichen ist aber op[0].<br />
Zweitens kannst du einen pointer nicht mit einem string literal vergleichen. Da musst du strcmp benutzen.</p>
<p>Am besten wäre es aber, wenn du std::string benutzt. Dann läuft dsa ganze intuitiver:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;
int main()
{
    int zahl1;
    int zahl2;
    string operator;
    cout &lt;&lt;&quot;erste Zahl eingeben!&quot; &lt;&lt;  endl;
    cin &gt;&gt;zahl1;
    cout &lt;&lt;&quot;Operationszeichen eingeben! -&gt; +,-,*,/&quot; &lt;&lt;  endl;
    cin &gt;&gt;op;
    cout &lt;&lt;&quot;zweite Zahl eingeben!&quot; &lt;&lt;  endl;
    cin &gt;&gt;zahl2;
    if (op == &quot;+&quot;)
    {
        cout &lt;&lt; zahl1 + zahl2 &lt;&lt;  endl;
    }
    if (op == &quot;-&quot;)
    {
        cout &lt;&lt; zahl1 - zahl2 &lt;&lt;  endl;
    }
    if (op == &quot;*&quot;)
    {
        cout &lt;&lt; zahl1 * zahl2 &lt;&lt;  endl;
    }
    if (op == &quot;/&quot;)
    {
        cout &lt;&lt; zahl1 / zahl2 &lt;&lt;  endl;
    }
    return 0;
}
</code></pre>
<p>In dem Falle könntest du statt string auch char nehmen und mit '+' (usw) vergleichen (aber nicht &quot;+&quot; ! )</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1767181</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767181</guid><dc:creator><![CDATA[sdfsdg]]></dc:creator><pubDate>Wed, 26 Aug 2009 17:16:58 GMT</pubDate></item><item><title><![CDATA[Reply to Rechner schreiben -&amp;gt; if problem on Wed, 26 Aug 2009 17:17:46 GMT]]></title><description><![CDATA[<p>edit: statt string operator; muss es natürlich string op; heißen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1767182</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767182</guid><dc:creator><![CDATA[assgs]]></dc:creator><pubDate>Wed, 26 Aug 2009 17:17:46 GMT</pubDate></item><item><title><![CDATA[Reply to Rechner schreiben -&amp;gt; if problem on Wed, 26 Aug 2009 17:24:24 GMT]]></title><description><![CDATA[<p>thx für die schnelle und klare hilfe ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1767187</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767187</guid><dc:creator><![CDATA[amMaster]]></dc:creator><pubDate>Wed, 26 Aug 2009 17:24:24 GMT</pubDate></item><item><title><![CDATA[Reply to Rechner schreiben -&amp;gt; if problem on Wed, 26 Aug 2009 17:28:51 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;

using std::cout;
using std::cin;
using std::endl;

int main()
{
    int zahl1;
    cout &lt;&lt;&quot;erste Zahl eingeben!&quot; &lt;&lt;  endl;
    cin &gt;&gt;zahl1;

    char op;
    cout &lt;&lt;&quot;Operationszeichen eingeben! -&gt; +,-,*,/&quot; &lt;&lt;  endl;
    cin &gt;&gt;op;

    int zahl2;
    cout &lt;&lt;&quot;zweite Zahl eingeben!&quot; &lt;&lt;  endl;
    cin &gt;&gt;zahl2;

    int ergebnis(zahl1);
    switch(op)
    {
        case '+':
            ergebnis += zahl2; break;
        case '-':
            ergebnis -= zahl2; break;
        case '*':
            ergebnis *= zahl2; break;
        case '/':
            ergebnis /= zahl2; break;
        default:
            cout &lt;&lt; &quot;falsche eingabe!&quot;; return 1;
    }

    cout &lt;&lt; ergebnis &lt;&lt; endl;
}
</code></pre>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1767191</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1767191</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Wed, 26 Aug 2009 17:28:51 GMT</pubDate></item></channel></rss>