Skip to content

MyUstaadG

Learn to Serve

  • Computer Science
    • Software
    • Computer Tips
    • Coding
      • Conditional Structures Exercises
      • Loops Exercises
      • Arrays Exercises
      • Python Exercises
    • Microsoft Office
      • MS Excel
      • MS Word
  • Videos
    • Funny Videos
    • Health and Fitness Videos
    • PUBG Videos
    • Technology Videos
  • News
  • Funny
  • Memes
  • Playwright Tutorials
  • Tutorials
  • Toggle search form
Write a Program to Build a Simple Calculator in C++

Write a Program to Make a Simple Calculator in C++ Programming Language | Solved Programming Exercises

Posted on September 26, 2021September 26, 2021 By myustaadg.com
Spread the love

Write a Program to Make a Simple Calculator in C++ Programming Language | Solved Programming Exercises

In this tutorial we will write a program in C++ Language to build a simple calculator. We will take two numbers from user and an operator. if operator is ‘+’ then add both numbers and so on.

We will use Dev C++ Compiler as an IDE.

How to install Dev C++ Compiler? Watch the Following Video.

How to install Dev C++ Compiler

So let’s Code in C++ Programming Language.

First of All, Create a C++ File then Include following Header Files:

#include"iostream"
using namespace std;

Above Header File is Used for Input and Output Purposes.

Second Step, take input from user.

main()
{
	int a,b;
	char op;
	cout<<"Enter First Number = ";
	cin>>a;
	cout<<"Enter Operator(+,-,*,/) = ";
	cin>>op;
	cout<<"Enter Second Number = ";
	cin>>b;
}

Next Step apply if condition to checker whether an operator is +,-,*/.

if(op == '+')
	{
		cout<<"Sum  = "<<a+b;
	}
	else if(op == '-')
	{
		cout<<"Minus = "<<a-b;
	}
	else if(op == '*')
	{
		cout<<"Mul = "<<a*b;
	}
	else if(op == '/')
	{
		if(b == 0)
		{
			cout<<"Cannot divide by zero";
		}
		else
		{
			cout<<"Div"<<a/b;
		}
	}
	else
	{
		cout<<"Invalid Operator";
	}

Write a Program to Make a Simple Calculator in Java Programming Language | Solved Programming Exercises

Write a Program to Make a Simple Calculator in C# Programming Language | Solved Programming Exercises

Finally Complete Code is Here:

//write a program to build
 a simple calculator in C++
#include"iostream"
using namespace std;
main()
{
	int a,b;
	char op;
	cout<<"Enter First Number = ";
	cin>>a;
	cout<<"Enter Operator(+,-,*,/) = ";
	cin>>op;
	cout<<"Enter Second Number = ";
	cin>>b;
	if(op == '+')
	{
		cout<<"Sum  = "<<a+b;
	}
	else if(op == '-')
	{
		cout<<"Minus = "<<a-b;
	}
	else if(op == '*')
	{
		cout<<"Mul = "<<a*b;
	}
	else if(op == '/')
	{
		if(b == 0)
		{
			cout<<"Cannot divide by zero";
		}
		else
		{
			cout<<"Div"<<a/b;
		}
	}
	else
	{
		cout<<"Invalid Operator";
	}
	
	
}

Hope You will learn something new here.

Write a Program to Make a Simple Calculator in C++ Programming Language

Watch the Video.

Write a Program to Build a Simple Calculator in C++

Programming Exercises Tags:C++ programming exercises, c++ programming lectures, calculator in c++, How to download and install Dev C++ Compiler, Make a Simple Calculator in C++, myustaadg, program to build a calculator, programming in c++, Solved Programming Exercises, solved programming exercises in c++, Write a Program to Build a Simple Calculator in C++, Write a Program to Make a Simple Calculator in C++ Programming Language, Write a Program to Make a Simple Calculator in C++ Programming Language | Solved Programming Exercises

Post navigation

Previous Post: How to Check Internet Speed | Internet Meter for Testing Real Internet Speed | Internet Speed Tester
Next Post: Write a Program to Make a Simple Calculator in Java Programming Language | Solved Programming Exercises

More Related Articles

Write a program that asks the user for an integer and shows on the screen whether it is even or odd | Python Programming Programming Exercises
Write a program that inputs the names of students of a class and displays them in ascending and descending order. Arrays Exercises
Write a program that uses three arrays ‘A’, ‘B’, and ‘C’. It inputs integer values in array ‘A’. In second array ‘B’, it stores the squares of values of array ‘A’ and in third array ‘C’, it stores cubes of the values of ‘A’. Arrays Exercises
Write a program that deletes a value from a specified location of one-dimensional array of N elements. Arrays Exercises
Write a program which input age from user and display on the screen if he/she is of legal age or not | Python Programming Programming Exercises
Write a program that inserts a new value at a specified location into one-dimensional array of N elements. Arrays Exercises

Copyright © 2022 MyUstaadG.

Powered by PressBook Blog WordPress theme