• # Thread: how to make a simple c++ calculator

1. ## how to make a simple c++ calculator

hello guys, this is my first post here and my first program...
i like c++, but its hard for first language, so i stopped for some time and i´m currently learning c#

Code:
```#include "stdafx.h" // only needed for microsoft compiler
#include &lt;iostream&gt;

using namespace std;

int main()
{
long double w,i,t; // declaring the first and second operator, and result
char h; // declaring the operator choice and at the same time, the choice of using the calculator again

cout &lt;&lt; "Simple Calculator\n" &lt;&lt; "Write the first number:" &lt;&lt; endl; // simple text output
cin &gt;&gt; w; // waiting for input
cout &lt;&lt; "Now write the second number:\n";
cin &gt;&gt; i;
cout &lt;&lt; "And the Operator:\n";
cin &gt;&gt; h;

if (h == '+') // comparing the opperator
t = w + i;
if (h == '-')
t = w - i;
if (h == '/')
t = w / i;
if (h == '*')
t = w * i;

cout &lt;&lt; "\nThe result is: " &lt;&lt; t &lt;&lt; endl &lt;&lt; "If you want to use the calculator again press \"y\"...\n"; // show the result
cin &gt;&gt; h;

if (h == 'y')
{
system ("cls"); // clear console screen
return main(); // restart calculator
}
else
return 0; // quit calculator
}```
this is very simple, but can help some beginners and i would like some feedback

2. ## Re: how to make a simple c++ calculator

Nice and simple, but good program for a beginner

Fleep

3. ## Re: how to make a simple c++ calculator

Nice and easy way to get people into a little bit of coding there WiTH def liking it!

4. ## Re: how to make a simple c++ calculator

Another neat idea, is to make a switch:case menu with options you want Addition, Substraction etc, etc.

5. ## Re: how to make a simple c++ calculator

Another neat idea, is to make a switch:case menu with options you want Addition, Substraction etc, etc.
cases ftw! May also be an idea to get them in the habit of checking if the input is valid or not using a FOR and the 'isdigit' function...in this numeric case.

6. ## Re: how to make a simple c++ calculator

thanks fleep and flyjunkie
the switch case sounds a good idea, but im more used to if statements :P