calculator with c++

// This is for beginners

#include <iostream>

using namespace std;

void greetings() {
    cout << "welcome to the calculator made in c++ :D\n";
}

void instructions() {
    cout << "Here is the operators you can use + - / *\n";
}

int main()
{
    greetings();
    instructions();
    int num1, num2;
    char op;
    int result;
    char again = 'Y';

    while (again == 'y' || again == 'Y') {



        cout << "\nEnter your first digit: ";
        cin >> num1;

        cout << "\nEnter your operator digit: ";
        cin >> op;

        cout << "\nEnter your second digit: ";
        cin >> num2;

        if (op == '+') {
            result = num1 + num2;
        }
        else if (op == '-') {
            result = num1 - num2;
        }
        else if (op == '*') {
            result = num1 * num2;
        }
        else if (op == '/') {
            result = num1 / num2;
        }
        else {
            cout << "Invalid operator";
        }

        cout << "= " << result;
        cout << "\nDo you want to restart the calculator? (Y or N)";
        cin >> again;
    }

    system("pause>0");

    return 0;
}

4.33
6
IllusiveBrian 18110 points

                                    #include &lt;iostream&gt;

using namespace std;

int main()
{
int num1;
int num2;
char op;
  
  cout &lt;&lt; &quot;Enter a number:&quot; &lt;&lt; endl;
  cin &gt;&gt; num1; //takes input
  
  cout &lt;&lt; &quot;Enter another number:&quot; &lt;&lt; endl; //prints some prompt
  cin &gt;&gt; num2;
  
  cout &lt;&lt; &quot;Enter a operator:&quot; &lt;&lt; endl; //prints some prompt
  cin &gt;&gt; op;
  
  if(op == '+')
  {
  cout &lt;&lt; &quot;Result = &quot; &lt;&lt; num1 + num2 &lt;&lt; endl;
  }else if(op == '-'){
  cout &lt;&lt; &quot;Result = &quot; &lt;&lt; num1 - num2 &lt;&lt; endl;
  }else if(op == '*'){
  cout &lt;&lt; &quot;Result = &quot; &lt;&lt; num1 * num2 &lt;&lt; endl;
  }else if(op == '/'){
  cout &lt;&lt; &quot;Result = &quot; &lt;&lt; num1 / num2 &lt;&lt; endl;
  }
  
  
}

4.33 (6 Votes)
0
4
3
Krish 100200 points

                                    #include &lt;iostream&gt;
using namespace std;

int main()
{
	int choice;

	cout &lt;&lt; 1 &lt;&lt; endl;
	cout &lt;&lt; 2 &lt;&lt; endl;
	cout &lt;&lt; 3 &lt;&lt; endl;
	cout &lt;&lt; 4 &lt;&lt; endl;

	cout &lt;&lt; &quot;Choice A Number: &quot;;
	cin &gt;&gt; choice;

	if (choice &gt;= 1 &amp;&amp; choice &lt;= 4)
	{
		int a, b;

		cout &lt;&lt; &quot;Enter Num One: &quot;;
		cin &gt;&gt; a;
		cout &lt;&lt; &quot;Enter Num Two: &quot;;
		cin &gt;&gt; b;

		if (choice == 1)
			cout &lt;&lt; a &lt;&lt; &quot;+&quot; &lt;&lt; b &lt;&lt; &quot;=&quot; &lt;&lt; a + b &lt;&lt; endl;
		if (choice == 2)
			cout &lt;&lt; a &lt;&lt; &quot;-&quot; &lt;&lt; b &lt;&lt; &quot;=&quot; &lt;&lt; a - b &lt;&lt; endl;
		if (choice == 3)
			cout &lt;&lt; a &lt;&lt; &quot;*&quot; &lt;&lt; b &lt;&lt; &quot;=&quot; &lt;&lt; a * b &lt;&lt; endl;
	}
	else
	{
		cout &lt;&lt; &quot;Wrong Choice&quot; &lt;&lt; endl;
	}
}

4 (3 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
calculator function c++ code c++ calculator building a calculator in c++ code calculator c++ how to make a simple calculator program in c++ c++ calculator code calculator program in cpp using class Function Calculator c++ simple calculator using function in c++ make a simple calculator in c++ calculator cpp which coding standard to use to make a calculator c++ calculator program in c++ how to make a calculator in c++ using class how to make a calculator in c++ using functions how to make calculator in c++ calculator in c++ builder code of calculator in c++ c++ code for calculator make a calculator in c++ making a calculator c++ develop a c++ program to implement simple calculator basic calculator c++ code for calculator in cpp calculator with cpp c++ program calculator how to make a calculator in c++ build a calculator in c++ How to create a calculator in c++ cpp calculator c++ calculator to code calculator in c++ using class simple c++ calculator code c++ calculator using functions calculator c++ c++ calculator by using functions create a calculator in c++ crate a calculator in c++ calculator using c++ simple calculator using c++ calculus in C++ calculator c++ solution create a c++ function the calculator calculator with c++ how to do a calculator in c++ simple c++ calculator c ++ calculaor c++ calculator script how to build a calculator in c++ calculator code c++ c++ calculator calculator in c++ how do do a calculator in c++ c++ calculator program code for calculator in c cpr calculator c++ calculator program advance c++ simple calculator how to build calculator in c++ c++ calculator using file how to build a calculator using c++ build a calculator c++ c++ making a calculator c++ calculator with menu calculation module is an example of in c++ how to make calc in cpp how to program a calculator in c++ c++ math calculator c++ calculator programme how to implement a calculator c++ making a simple calculator in c++ how to make a basic calculator in c++ c++ calculator project C++ calculator logic simple calculator c++ how to create calculator in c++ 2 digitcalculater cpp progrram making a calculator in c++ c++ write a simple calculator using a switch statement c++ how to make a calculator cpp code for calculator how to write a calculate in c++
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source