55+ CPP Calculator Examples

This post contains a total of 55+ Hand-Picked C++ Calculator Examples. All the C++ Calculators are made purely using C++ Programming Language.

You are free to use the source codes of these C++ calculators for educational use with credits to the original owner. If you need the source code for some other work then you should contact the owner.

Related Posts

Click a Code to Copy it, and Hover over a video to play it.

1. By ff22ff

Made by ff22ff. Enter the operation in single line with space between the number and the operator like – 2 + 2. ( Source )

#include <iostream>
using namespace std;
/*Hello friend, this is a small number calculator program you need to drive by this example: "digit" space "mathematical sign" space "digit" 2 + 2          | plz like*/
int main() {
float a, b;
char k;
cin >> a >> k >> b;
    switch (k){
             
             case'+':
                 cout<<a<<"+"<<b<<"="<<a+b
                     <<endl;
                break;
            
             case'-':
                 cout<<a<<"-"<<b<<"="<<a-b
                     <<endl;
                break;
            
             case'*':
                 cout<<a<<"*"<<b<<"="<<a*b
                     <<endl;
                break;
             
             case '/':
                             cout<<a<<"/"<<b<<"="<<a/b
                         <<endl;
                break;
                }
                cout << "plz like my code\n"<< ">>by ff22ff<<" << endl ;
    return 0;
}

2. By SparkerXof

C++ Calculator by SparkerXof. Enter the operation in different lines, first enter 1st number then the 2nd number after that the operator. ( Source )

#include <iostream>
using namespace std;

int main() {
    double var1; //Create variables
    double var2;
    double total;
    char oper;
    char answer;
    
    cout << "Print first variable: "; //Set varriables
    cin >> var1;
    cout << "\nPrint second variable: ";
    cin >> var2;
    cout << "\nPrint operator: ";
    cin >> oper;
    
    switch (oper) {
        case '+':
            total = var1 + var2; //Cheak operators
            break;
        case '-':
            total = var1 - var2;
            break;
        case '*':
            total = var1 * var2;
            break;
        case '/':
            total = var1 / var2;
            break;
        default:
            cout << "\nYou must write +, -, * or /." << endl;
    }
    
    cout << "\nTotal: " << total << endl; //View total
    
    return 0;
}

3. By Kieran Lunt

Made by Kieran Lunt. Enter operation in different lines, enter first number then operator in second line and the second number in third line. ( Source )

#include <iostream>
using namespace std;

int main() {
int i;
string e;
int u;
cin >> i;
cin >> e;
cin >>u; 
if(e == "+"){
    cout << i + u << "\n";
}
if(e == "-"){
  cout << i - u << "\n";    
}
if(e == "*"){
    cout << i * u << "\n";
}
if(e == "/"){
    cout << i / u << "\n";
}
	return 0;
}

4. By Abhijeet Kumar

Made by Abhijeet Kumar. In the first two lines enter two digits and in the third line enter an operator. ( Source )

#include <iostream>
using namespace std;
int main()
 { float op1, op2, res ;
 char ch ;        
 cout <<"Two numbers you entered: ";
 cin >> op1 >>op2 ;
 cout << op1 << " , " << op2 ;
 cout <<"\n"<<"The operator you entered(+, -, *, /, %) : " ;
 cin >> ch;
 cout << ch;
 cout <<"\n";
 switch (ch)
 { case '+' : res=op1+op2;
             break ;
   case '-' : res=op1 - op2;
             break ;
   case '*' : res = op1 * op2;
             break ;
   case '/' : if (op2 == 0)
                   cout <<"Divide by zero error!!!";
              else 
                  res = op2 / op1;
              break ;
    case '%' : if (op2 == 0)
                    cout <<"Divide by zero error!!!";
               else 
                {   int r,q;
                    q = op2 / op1;
                    r = op2 - (q * op1);
                    res = r;
                }
                break ;
    default : cout <<"\n"<<"Wrong operator!!!";
 }
 cout <<"The calculated result is :"<< res<<"\n";
}

5. By J.G

Made by J.G. To use, enter in your first number, the operator, then the second number. Operators can be +,-,*,/,%, and ^. ( Source )

/* Made by J.G.
Thanks to Senpai Filip for showing me how to declare variables as doubles then use them as integers later.
*/

#include <iostream>
#include <cmath>

using namespace std;

int main() {
    char o;
    double x, y;
    
    cin>>x>>o>>y;
    
    switch(o){
    
    case '+':
    cout<<x<<" + "<<y<<" = "<<x+y;
    break;
    
    case '-':
    cout<<x<<" - "<<y<<" = "<<x-y;
    break;
    
    case '/':
    if(y==0){
       cout<<"Cannot divide by 0!";
    }
    else{
       cout<<x<<"/"<<y<<" = "<<x/y;
    }
    break;
    
    case '*':
    cout<<x<<" * "<<y<<" = "<<x*y;
    break;
    
    case '%':
    cout<<int(x)<<" % "<<int(y)<<" = "<<int(x) % int(y);
    break;

    case'^':
    cout<<x<<" ^ "<<y<<" = "<<pow(x,y);
    break;
    
    default:
    cout<<"Please enter a valid operation. Valid operations are +,-,*,/,%, and ^"<<endl;
    break;
    }
    
    cout<<endl<<"Please leave a like and any suggestions in the comment section! Is there anything that I should add?";
    return 0;
}

6. By ๐™Ž๐™ž๐™ข๐™ง๐™–๐™ฃ ๐Ÿ’ซ

Made by ๐™Ž๐™ž๐™ข๐™ง๐™–๐™ฃ ๐Ÿ’ซ. Enter the two numbers of the operation in one single line with space in between. ( Source )

    /*๏ฝกโ˜†โœผโ˜…โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ˜…โœผโ˜†๏ฝก
           ๐˜พ๐™ง๐™š๐™–๐™ฉ๐™š๐™™ ๐˜ฝ๐™ฎ 
                ๐™Ž๐™ž๐™ข๐™ง๐™–๐™ฃ ๐Ÿ’ซ
/* 
 ENTER THE TWO VALUES
      Ex:- 2  5  
*/
 
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
float x, y;

cin>> x >> y;
cout<<"\n\n\n";
cout<< setw(10) << x << setw(2) 
<< "+" <<setw(2) << y <<setw(2)
<< " = " <<setw(1) << x+y << endl;

cout<< setw(10) << x << setw(2)
<< "-" <<setw(2) << y <<setw(2) 
<< " = " <<setw(1) << x-y << endl;


cout<< setw(10) << x << setw(2) 
<< "*" <<setw(2) << y <<setw(2) 
<< " = " <<setw(1) << x*y << endl;


cout<< setw(10) << x << setw(2) 
<< "/" <<setw(2) << y <<setw(2) 
<< " = " <<setw(1) << x/y << endl;

cout<< "\n\n\n\t Thank you for visiting ๐Ÿซ๐Ÿค—";
cout<<"\n\n\t ยฉ๏ธ Simran ";
return 0;
}

7. By Collin

Made by Collin. Enter the operation in single line with no space in between the number and the operator. ( Source )

#include <iostream>
using namespace std;

int main() {
int a, b;
int sum;
cout << "calculator \n";
cin >> a;
cin >> b;
sum = a + b;
cout << a; 
cout << " + ";
cout << b;  
cout << " = ";
cout << sum;

    return 0;
}

8. By Satyam Keshri

Made by Satyam Keshri. First enter two numbers in single line with space in between, after that select the operator you want to use. ( Source )

#include <iostream>
using namespace std;

class calculator{
    double num1, num2;
    public :
    calculator (double n1, double  n2){
        num1 =n1;
        num2 = n2;
    }
    void input( double n1, double n2){
        num1 =n1;
        num2 =n2;
    }
    double add(){
        return num1 + num2 ;
    }
    double sub(){
         return num1 - num2 ;
    }
    double mult(){
         return num1 * num2 ;
    }
    double div(){
        return num1/num2;
    }
};

int main() {
    calculator obj(10,15);
    int choice=0; // i=0;
    do{
     /*   cout<<"\n\n\nSelect any index of Array. (<5)\n";
        cin>>i;
        if(i>4)
            cout<<"\nEnter a valid index";
        else{*/
        double num1  , num2 ;
        cout<<"\nEnter two numbers : ";
        cin>>num1 >>num2 ;
        obj.input(num1 ,num2 );
        cout<<"\nSelect an option"<<endl;
        cout<<"\nADDITION -> 1\nSUBSTRACTION -> 2\nMULTIPLICATION -> 3\nDIVISION-> 4\nEXIT ->0\n";
        cin>>choice;
        switch(choice){
            case 1 :
                    cout<<"\nAddition of numbers = "<<obj.add();
                    break;
            case 2 : 
                    cout<<"\nSubstraction of numbers = "<<obj.sub();
                    break;
            case 3 :
                    cout<<"\nMultiplication of numbers = "<<obj.mult();
                    break;
            case 4 :
                    cout<<"\nDivision of numbers = "<<obj.div();
            case 0 :
                    choice=0;
                    break;
            default :
                    cout<<"\nInvalid Selection\tPlease enter valid option\n";
                    break;
        }
    }
    while(choice !=0);
    
    return 0;
}

9. By Fedor Kovalenko

Made by Fedor Kovalenko. Enter the first number, mathematical operation and the second number. The space is not required. ( Source )


#include <iostream>
#include <cmath>
using namespace std;

int main() {
    double  number1,number2, result;
    char oper;
    //cout<<"Enter the number1: ";
    cin>>number1;
    //cout<<"Enter operation: ";
    cin>>oper;
    //cout<<"Enter the number2: ";
    cin>>number2;
    cout<<"Number1: "<<number1<<endl;
    cout<<"Operation: "<<oper<<endl;
    cout<<"Number2: "<<number2<<endl;
    if (oper=='+') {
        result=number1+number2;
    }
    else if (oper=='-') {
        result = number1-number2 ;
    }
    else if (oper=='*') {
        result = number1*number2 ;
    }
    else if (oper=='/') {
        result = number1/number2;
    }
    else if (oper=='^') {
        result = pow(number1,number2);
    }
    else {
        cout<<endl<<"There is no such mathematical operation"<<endl;
    }
    cout<<endl<<number1<<oper<<number2<<" = "<<result<<endl;
}  //Thanks!

10. By Artem Kozlov

C++ Calculator by Artem Kozlov. Enter operator in single line with or without space in between. ( Source )

#include <iostream>

using namespace std;

int main()
{

    double  a;   
    char b;
    double  c;
    double  z;
   cin>>a;
   cin >> b;
   cin >> c;
   if (b == '+'){
   z = a + c;
   }
   if (b == '-'){
   z = a - c;
   }
   if (b == '/'){
   z = a / c;
   }
   if (b == '*'){
   z = a*c;
   }
   cout << z << endl;
}

11. By The future is now thanks to science

Made by The future is now thanks to science. The program supports multiple operators and numbers. Enter the operation in one single line. ( Source )

#include <iostream>
using namespace std;
int main() {
    //For less than or equal 100 numbers.support +,-,*,/
    //hope you like it
    float num[100];
    char sym[100];
    int i,j;
    int k=0;
    for(i=0;i<100;i++)
    {
        cin>>num[i];
        cin>>sym[i];
        if(sym[i]=='=')
        {
            break;
        }
        
    }
    for(j=0;j<i;j++)
    {
        while(1)
        {
        if(sym[j]=='/')
        {
            k=j+1;
            num[j]=num[j]/num[k];
            
            for(;k<i;k++)
            {
                num[k]=num[k+1];
                sym[k-1]=sym[k];
            }
        }
        if(sym[j]!='/')
        {
            break;
        }
        else
        {
            continue;
        }
        }
        }
    for(j=0;j<i;j++)
    {
        while(1)
        {
        if(sym[j]=='*')
        {
            k=j+1;
            num[j]=num[j]*num[k];
            
            for(;k<i;k++)
            {
                num[k]=num[k+1];
                sym[k-1]=sym[k];
            }
        }
        if(sym[j]!='*')
        {
            break;
        }
        else
        {
            continue;
        }
        }
        }
        
    for(j=0;j<i;j++)
    {
        while(1)
        {
        if(sym[j]=='-')
        {
            k=j+1;
            num[j]=num[j]-num[k];
            
            for(;k<i;k++)
            {
                num[k]=num[k+1];
                sym[k-1]=sym[k];
            
            }
        }
        if(sym[j]!='-')
        {
            break;
        }
        else
        {
            continue;
        }
        }
        }
    for(j=0;j<i;j++)
    {
        while(1)
        {
        if(sym[j]=='+')
        {
            k=j+1;
            num[j]=num[j]+num[k];
            
            for(;k<i;k++)
            {
                num[k]=num[k+1];
                sym[k-1]=sym[k];
            }
        }
        if(sym[j]!='+')
        {
            break;
        }
        else
        {
            continue;
        }
        }
    }
    cout<<"Your answer is ";
    cout<<num[0];      
    }

12. By Demoshell

Made by Demoshell. Enter operation in single line. ( Source )

#include <iostream>
#include <math.h>
using namespace std;
void math(){
    cout<<"Enter a math operation: ";
    char op; float n1; float n2; float result;
    cin>>n1;
    cin>>op;
    cin>>n2;
    switch(op)
        {
        case '+':
    result = n1 + n2;
    break;
    
    case '-':
        result = n1 - n2;
        break;
        
        case '*':
        case 'x':
            result = n1 * n2;
        break;
    case '^':
        result = pow(n1, n2);
    break;        
    case '/':
    result = n1 / n2;
    break;
    default:
    cout<<"\nError, please try again";
};
cout<<"\nThe result is: "<<result;
}
int main() {
math();
    return 0;
}

13. By Yuri Gagarin

Made by Yuri Gagarin ( Not the astronaut one ). Enter operation in single line without spaces in between operator and numbers. ( Source )

#include <iostream>

using namespace std;  
  
int main()  
{  
    double x = 0.0;
    double y = 0.0; 
    double result = 0.0;
    char oper = '+';

    cout << "Calculator [C++]" << endl;
    cout <<"------------------" << endl << endl;  
    
    
        cin  >> x  >> oper  >> y;
        if (oper == '/' && y == 0)
        {
            cout << "Uff! An error has ocurred." << endl;
            
        }
        else
        {
            if(oper == '+'){
                result = x + y;
            }
            else if(oper == '-'){
                result = x - y;
            }
            else if(oper == '*'){
                result = x * y;
            }
            else if(oper == '/'){
                result = x / y;
            }
            else{
                cout << "Unexpected operator" << endl;
            }
        }
        cout << "Result is: " << result << endl;
    

    return 0;  
}

14. By Senan

Made by Senan. Input should be like this ” number operation  number”, all in different lines. ( Source )

#include <iostream>
using namespace std;

int main() {
double  x,y;
char c;
cin>>x; // input the first number
cin>>c; // input the operation  (+,-,*,/)
cin>>y; // input the second number 
switch (c){
     case '+' : cout <<x<<"+"<<y<<"="<<x+y;
                break ;
     case '-' : cout <<x<<"-"<<y<<"="<<x-y;
                break ;
     case '*' : cout <<x<<"*"<<y<<"="<<x*y;
                break ;
     case '/' : if(y==0){
               cout <<"error:You can't divide by zero"; 
                  break ;}       
                else {
               cout <<x<<"/"<<y<<"="<<x/y;
                break ;}
     default :cout <<" wrong operation :(";
                
          }
    return 0;
}

15. By Suraj Mane

C++ Calculator by Suraj Mane. Enter the two numbers of the operation in one single line with space in between, after that press enter and select the operator. ( Source )

// Created by Suraj Mane


//Give gaps in numbers when entering numbers.!
/*Give minimum two gaps for entering your choice & numbers!*/
//enter only three numbers..
//enter third number between  1 to 5 is compulsory!!!!!


//enter like this onr 56 57 2....

#include <iostream>
using namespace std;

int main() {

    int no1,no2,result,choice;
    cout<<"Enter two numbers: " <<endl;
    cin>>no1>>no2;
    cout<<"\nYou entered:"<<no1<<" & "<<no2 <<endl;
    cout<<"\n1.Add\n2.Subtract\n3.Multiply\n4.Divide\n5.Modules\nEnter your choice:"<<endl;
    cin>>choice;
    cout<<"\nYou choice is To "<<choice<<endl;
    switch(choice)
     {
         case 1:result=no1+no2;
         cout<<"\nAnswer is "<<result<<endl;
         break;
         
         case 2:result=no1-no2;
         cout<<"\nAnswer is "<<result<<endl;
         break;
         
         case 3:result=no1*no2;
         cout<<"\nAnswer is "<<result<<endl;
         break;
         
         case 4:result=no1/no2;
         cout<<"\nAnswer is "<<result<<endl;
         break;
         
         case 5:result=no1%no2;
         cout<<"\nAnswer is "<<result<<endl;
         break;
         
         default:cout<<"\n Invalid choice\n plz only choose between 1 to 5!!!"<<endl;
     }
    return 0;
}

16. By Hussain Ali

Made by Hussain Ali. Enter operation in single lines, enter first number then the operator and after that the second number. ( Source )

#include <iostream>
using namespace std;

int main(){
    double a,b,c;
char d[5]={'+','-','*','/','%'};
char od;
   cout<<"Please enter the number \t";
    cin>>a;
    cout<<"what you want to do \t ";
    cin>>od;
    cout<<"Provide the 2nd Value \t";
    cin>>b;
    if(od==d[0])
    c=a+b;
    if(od==d[1])
    c=a-b;
    if(od==d[2])
    c=a*b;
    if(od==d[3])
    c=a/b;
    if(od==d[4])
    c=a/b*100;
    cout<<endl<<"Your result is: "<<c;
    
    return 0;
}

17. By Eugene Shapovalov

Made by Eugene Shapovalov. Enter first number then the operator and at last the second number. ( Source )

#include <iostream>
using namespace std;

int main() {
float a,b,c;
char sym;
cout<<"Enter the first number \n";
cin>>a;
cout<<"Choose option \n";
cin>>sym;
cout<<"Enter the second number \n";
cin>>b;
switch (sym){
 case '+':
     c=a+b;
     cout<<c<<endl;
 break;
 case '-':
     c=a-b;
     cout<<c<<endl;
 break;
 case '*':
     c=a*b;
     cout<<c<<endl;
 break;
 case '/': 
     c=a/b;
     cout<<c<<endl;
 break;
 default:
 cout<<"Error"<<endl;
 break;}
    return 0;
}

18. By โœจSARANGโœจ

Simple C++ Calculator by โœจSARANGโœจ. Enter first number then operator and after that the second number, all in different lines. ( Source )

#include <iostream>
using namespace std;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Made by โœจSARANGโœจยฉยฎ
//enter the equation:
//input example : 5+8
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int main()
 {
 int num1,num2,result,reminder;
 char operation;
 
 cin>>num1;
 cin>>operation ;
 cin>>num2;
 
 switch(operation)
 {
     case '+':
     printf("You choose addition\n");
     result =num1+num2;
     cout<<"The answer is:";
     cout<<result;
     break;
     
     case '-':
     cout<<"You choose subtraction"<<endl;
     result=num1-num2;
     cout<<"The answer is:";
     cout<<result;
     break;
     
     case '*':
     cout<<"You choose multiplication"<<endl;
     result=num1*num2;
     cout<<"The answer is:";
     cout<<result;
     break;
     
     case '/':
     cout<<"You choose division"<<endl;
     result=num1/num2;
     reminder=num1%num2;
     cout<<"The quotient is:"<<result<<endl;
     cout <<"The reminder is:"<<reminder;
     break;
     
     default :
     cout<<"Invalid input pls enter valid input";
 }
    return 0;
}

19. By Rajan Kumar

Made by Rajan Kumar. First select the operator you want to use after that enter the two numbers. ( Source )

#include <iostream>
using namespace std;
void Addition();
void Subtraction();
void Division();
void Multiplication();
void Modulus();

int main() 
{
	cout<<"\n What do you want to do?\n 1. Addition.\n 2. Subtraction.\n 3. Division.\n 4. Multiplication.\n 5. Modulus.\n";
	cout<<" Enter your choice : ";
	char choice;
	cin>>choice;
	switch (choice)
	{
	    case '1' : Addition();
	    break;
	    case '2' : Subtraction();
	    break;
	    case '3' : Division();
	    break;
	    case '4' : Multiplication();
	    break;
	    case '5' : Modulus();
	    break;
	    default  : printf("\n Enter valid option...\n");
	    break;
	}
	return 0;
}

void Addition()
{
    float a;
    float b;
    cout<<"\n Enter first number  : ";
    cin>>a;
    cout<<"\n Enter second number : ";
    cin>>b;
    float c=a+b;
    cout<<"\n Result is : "<<c;
}

void Subtraction()
{
    float a;
    float b;
    cout<<"\n Enter first number  : ";
    cin>>a;
    cout<<"\n Enter second number : ";
    cin>>b;
    float c=a-b;
    cout<<"\n Result is : "<<c;
}

void Division()
{
    float a;
    float b;
    cout<<"\n Enter first number  : ";
    cin>>a;
    cout<<"\n Enter second number : ";
    cin>>b;
    float c=a/b;
    cout<<"\n Result is : "<<c;
}

void Multiplication()
{
    float a;
    float b;
    cout<<"\n Enter first number  : ";
    cin>>a;
    cout<<"\n Enter second number : ";
    cin>>b;
    float c=a*b;
    cout<<"\n Result is : "<<c;
}

void Modulus()
{
    int a;
    int b;
    cout<<"\n Enter first number  : ";
    cin>>a;
    cout<<"\n Enter second number : ";
    cin>>b;
    int c=a%b;
    cout<<"\n Result is : "<<c;
}

20. By Roman Pervutinskiy

Made by Roman Pervutinskiy. Enter first number then operator, after that the second number all in different lines. ( Source )

/*
Example:
Input:
10
*
56
Output:
10*56=560
*/
#include <iostream>
using std::cout;
int main() {
    float a,c;
    char b;
    std::cin >> a >> b >> c;
    switch(b) {
        case '+': cout << a << b << c << '=' << a+c; break;
        case '-': cout << a << b << c << '=' << a-c; break;
        case '*': cout << a << b << c << '=' << a*c; break;
        case '/': cout << a << b << c << '=' << a/c;
    }
    return 0;
}

21. By Vikash Pal

Basic C++ Calculator by Vikash Pal. Input format – 23 45 3, where, 23 is a number, 45 is another number number and 3 is operation type. ( Source )

/*

There are 5 operations you can do.
1 for Division, 2 for Modulus, 3 for Multiplication, 4 for Addition and 5 for Substraction.

Example- 24 34 2 can be written as 24 % 34 == 24
*/

#include <iostream>

int main() {
    int num1, num2, op;
    std::cout << ">> Please enter a number." << std::endl;
    std::cin >> num1;
    std::cout << "<< You entered " << num1 << std::endl;
    std::cout << ">> Please enter another number." << std::endl;
    std::cin >> num2;
    std::cout << "<< You entered " << num2 << std::endl;
    std::cout << ">> Please select the operation you want." << std::endl;
    std::cout << "** Enter 1 for Division." << std::endl;
    std::cout << "** Enter 2 for Modulus." << std::endl;
    std::cout << "** Enter 3 for Multiplication." << std::endl;
    std::cout << "** Enter 4 for Addition." << std::endl;
    std::cout << "** Enter 5 for Substraction." << std::endl;
    std::cin >> op;
    
    switch(op) {
        case 1:
            std::cout << "<< You selected Division." << std::endl;
            std::cout << "<< And your result is " << num1/num2 << std::endl;
            break;
        case 2:
            std::cout << "<< You selected Modulus." << std::endl;
            std::cout << "<< And your result is " << num1%num2 << std::endl;
            break;
        case 3:
            std::cout << "<< You selected Multiplication." << std::endl;
            std::cout << "<< And your result is " << num1*num2 << std::endl;
            break;
        case 4:
            std::cout << "<< You selected Addition." << std::endl;
            std::cout << "<< And your result is " << num1+num2 << std::endl;
            break;
        case 5:
            std::cout << "<< You selected Substraction." << std::endl;
            std::cout << "<< And your result is " << num1-num2 << std::endl;
            break;
        default:
            std::cout << "<< Invalid Operation." << std::endl;
    }

  std::cout << "\n";

  std::cout << "Note: This code works best in Cxxdroid - Educational IDE for C/C++. Available at Google Play.";
    return 0;
}

22. By Emi

Made by Emi. Enter the operation in one single line without spaces in between the operator and numbers. ( Source )

#include <iostream>
using namespace std;

int main() {
float a, b, sum, dif, prod, div;
    char sign;
    cout<<"Calculator:\n";
    cin>>a;
    cin>>sign;
    if(sign == '+'){
    //does the addition
      cin>>b;
      sum = a+b;
      cout<<a<<'+'<<b<<'=';
      cout<<sum;
    }
    else if (sign == '-' ){
    //does the substraction
      cin>>b;
      dif = a-b;
      cout<<a<<'-'<<b<<'=';
      cout<<dif;
    }
    else if(sign == '*' ){
    //does the multiplication
      cin>>b;
      prod = a*b;
      cout<<a<<'*'<<b<<'=';
      cout<<prod;
    }
    else if (sign == '/' ){
    //does the division
      cin>>b;
      if(b == 0){
        cout<<"You can't divide by 0!!!";
        /*eliminates the possibility of b being zero so the program won t crash*/
      }
      else{
        div = a/b;
        cout<<a<<'/'<<b<<'=';
        cout<<div;
      }
    }
    else if(sign != '+' || sign != '-' || sign != '*' || sign != '/') {
      cout<<"Error!!!!! ";
      /*detects if a user inputs a letter instead of an operation
      sign and displays error if it s a letter*/
    }
    return 0;
    
}

23. By alex44098

Made by alex44098. First enter the operator you want after that enter the first and the second number. ( Source )

#include <iostream>
using namespace std;

int main()
{

/*
addition +
subtraction -
multiplication *
division /
the area of a circle %
the circumference of a circle @
example input:
/ 6 3 
or
@ 5
*/
    int a;
    int b;
    int x=2;
    double pi=3.14;
    char operation;
    cout<<"Enter the operation sign:"<<endl<<"addition:+"<<endl<<"subtraction:-"<<endl<<"multiplication:*"<<endl<<"division:/"<<endl<<"the area of a circle :%"<<endl<<"the circumference of a circle :@"<<endl;
    cin>>operation;
    switch(operation)
     {
     case'+':
    cout<<"Enter first number:"<<endl ;
    cin>>a;
    cout<<"Enter second number:"<<endl ;
    cin>>b;
    break;
     case'-':
    cout<<"Enter first number:"<<endl ;
    cin>>a;
    cout<<"Enter second number:"<<endl ;
    cin>>b;
    break;
     case'*':
    cout<<"Enter first number:"<<endl ;
    cin>>a;
    cout<<"Enter second number:"<<endl ;
    cin>>b;
    break;
     case'/':
    cout<<"Enter first number:"<<endl ;
    cin>>a;
    cout<<"Enter second number:"<<endl ;
    cin>>b;
    break;
     default:
       cout<<"Enter circle's radius:"<<endl ;
    cin>>a;
     }

    switch(operation)
    {
    case'+':
        cout<<a<<"+"<<b<<"="<<a+b<<endl;
        break;
       case'-':
        cout<<a<<"-"<<b<<"="<<a-b<<endl;
        break;
         case'*':
        cout<<a<<"*"<<b<<"="<<a*b<<endl;
        break;
        case'/':
        cout<<a<<"/"<<b<<"="<<a/b<<endl;
        break;
        case'@':
        cout<<"the circumference of a circle :"<<a*pi*x<<endl;
        break;
        case'%':
        cout<<"the area of a circle :"<<a*a*pi<<endl;
        break;
        default:
        cout<<"ERROR!!!!!!";
    }
    return 0;
}

24. By Saugat Jarif

Made by Saugat Jarif. Enter first number, after that the operator and after that the second number. All in different lines. ( Source )

#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;

// Created By - Saugat Jarif
// Created In - C++

// Please Copy This Code To Your Code Editor Then Run it

// Example Input:
// 1
// +
// 1

// output: 2

int main()
{
    // variables
    int Firstnumber;
    int Secondnumber;
    char selector;
    int sum;

    // number selection
    cout << "select the first number" << endl;
    cin >> Firstnumber;
    cout << "select an operator" << endl;
    cin >> selector;
    cout << "enter your second number" << endl;
    cin >> Secondnumber;

    // conditions
    
    
    // checks if divide by 0
    if (Firstnumber / Secondnumber && Firstnumber == 0 || Secondnumber == 0){ 
        cout << "NumError: Cant Divide By 0"<< endl;
    }
    if(Firstnumber == 0 || Secondnumber == 0){
        if(Firstnumber > Secondnumber){
            cout << Firstnumber << endl;
        }
        if(Firstnumber < Secondnumber){
            cout << Secondnumber << endl;
        }
    }
    
    // Conditions to what to do
    if (selector == '+') {
        sum = Firstnumber + Secondnumber;
    }
    if (selector == '-') {
        sum = Firstnumber - Secondnumber;
    }
    if (selector == '*') {
        sum = Firstnumber * Secondnumber;
    }
    if (selector == '/') {
        sum = Firstnumber / Secondnumber;
    }
    //output 
    cout << sum << endl;
return 0;
}

25. By Bodan Talev

Made by Bodan Talev. Your input should be something like this ->[num operator num] (example, 5+5) (example, 9~). ( Source )



#include <iostream>
#include <cstdlib>
#include <cmath>

using namespace std;

int main() {
    int a,b;
    char x;
    cin>>a>>x>>b;
    
    switch(x) {
        case '+':
            cout<<a<<"+"<<b<<"="<<a+b;
            break;
        case '-':
            cout<<a<<"-"<<b<<"="<<a-b;
            break;
        case '*':
            cout<<a<<"*"<<b<<"="<<a*b;
            break;
        case '/':
            cout<<a<<"/"<<b<<"="<<a/b;
            break;
        case '%':
            cout<<a<<"%"<<b<<"="<<a%b;
            break;
        case '^':
            cout<<pow(a,b);
            break;
        case '~':
            cout<<"~"<<a<<"="<<sqrt(a);
            break;
        default: cout<<"Error!";
    }
    return 0;
}

26. By Garvit dubey ๐Ÿ‡ฎ๐Ÿ‡ณ

C++ Calculator by Garvit dubey ๐Ÿ‡ฎ๐Ÿ‡ณ. Enter first number, then second number and at last the operator. ( Source )

#include <iostream>
using namespace std;

int main()
 {
    int a , b ;
    char ch ;
    cout << "Enter the first number" << endl ; 
    cin >> a ;
    cout << "First Number : " << a << endl ;
    cout << "Enter the second number" << endl ;
    cin >> b ;
    cout << "Second Number : " << b << endl ;
    cout << "Choose the operator " << endl ;
    cin >> ch ;
    if (ch=='+')
    {
        cout << "Sum is : " << a+b << endl ;
    }
    else if (ch=='-')
    {
        cout << "Difference is : " << a-b << endl ;
    }
    else if (ch=='*')
    {
        cout << "Product is : " << a*b << endl ;
    }
    else if (ch=='/')
    {
        cout << "Quotient is : " << a/b << endl ;
    }
    else if (ch=='%')
    {
        cout << "Remainder is : " << a%b << endl ;
    }
    else 
    cout << "Invalid" << endl ;
    return 0;
}

27. By Vincenzinho

Made by Vincenzinho. Enter 2 numbers with a space in between, like this 10 5. ( Source )



#include <iostream>
using namespace std;

int main() {

float a;
float b;
cout<<"first number: ";
cin>>a;
cout<<a<<endl;
cout<<"second number: ";
cin>>b;
cout<<b<<endl<<endl;

float sum=a+b;
float multiply=a*b;
float divide=a/b;
float divide2=b/a;
float minus=a-b;
float minus2=b-a;

cout<<a<<"+"<<b<<"="<<sum<<endl;
cout<<a<<"*"<<b<<"="<<multiply<<endl;
cout<<a<<"/"<<b<<"="<<divide;
if (b==0){cout<<"(you can't divide by 0)"<<endl;}
else {cout<<endl;}
cout<<b<<"/"<<a<<"="<<divide2;
if (a==0){cout<<"(you can't divide by 0)"<<endl;}
else {cout<<endl;}
cout<<a<<"-"<<b<<"="<<minus<<endl;
cout<<b<<"-"<<a<<"="<<minus2<<endl;

    return 0;
}

28. By Mahadi

Made by Mahadi. Enter operation in one single line, like 1+1 without any space in between. ( Source )

#include <iostream>
using namespace std;

int main() {

float x, y, hasil;
char aritmatika;

cout << "Calculator" << endl << endl;

cout << "Input first number = ";
cin >> x;
cout << endl;

cout << "input operator : ";
cin >> aritmatika;
cout << endl;

cout << "Input second number = ";
cin >> y;
cout << endl;

switch(aritmatika){
// (+)
 case '+':
 hasil = x + y;
 cout << x << " + " << y << " = " << hasil;
 break;
 
// (-)
 case '-':
 hasil = x - y;
 cout<< x <<" - " << y << " = " << hasil;
 break;

// (*)
 case '*':
 hasil = x * y;
 cout<< x <<" * " << y << " = " << hasil;
 break;
 
 // (/)
 case '/':
 hasil = x / y;
 cout<< x <<" / " << y << " = " << hasil;
 break;
 
 default:
 cout<< "You put wrong number! "<<endl;
 }
   
    return 0;
}

29. By nikoloz buava

Made by nikoloz buava. Enter two numbers to get the output of it when used with different operators. ( Source )

/* enter 2 whole numbers to calculate*/
#include <iostream>
using namespace std;

int main() {
    int x, y;
    cout << "Enter the first number: " << endl;
    cin >> x;
    cout << "Enter the second number: " << endl;
    cin >> y;
    int sum = x + y;
    cout << "Sum is:" << endl;
    cout << x << " + " << y << " = " << sum << endl;
    int difference = x - y;
    cout << "Difference is:" << endl;
    cout << x << " - " << y << " = " << difference << endl;
    int multiplied = x * y;
    cout << "Multiplied is:" << endl;
    cout << x << " * " << y << " = " << multiplied << endl;
     int division = x / y;
     cout << "Division is:" << endl;
     cout << x << " / " << y << " = " << division << endl;
     int b = x % y;
     cout << "Balance obtained during division is:" << endl;
     cout << x << " % " << y << " = " << b << endl;
    return 0;
}

30. By Jason ramirez

Made by Jason ramirez. First select the operator after that enter the first and the second number. ( Source )

#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    //-------defining variables and initializing them-------------
    double num1,num2;
    char operation,redo;
    //--------Printing my name on screen----------------
    cout<<"Welcome to the calculator program v.1.0 written by Jason Ramirez"<<endl;
    cout<<"***************************************************"<<endl;
    cout<<endl<<endl<<endl;
    //--here do loop is used so that the program can be used more then one time
    //without exiting the run screen---------------------------
    do
    {
        //----receiving the variables from input--------------
        cout<<" Please enter an operation which you like to calculate (+,-,*,/,s)";
        cout<<"[s stands for swap]:";
        cin>>operation ;
        cout<<endl<<endl;
        cout<<" Please enter two numbers to apply your requested operation(";
        cout<<operation<<"):"<<endl<<"1st num:";
        cin>>num1;
        cout<<"2nd num:" ;
        cin>>num2;
        cout<<endl;
        //---used switch function so thet the operater can be decided------------
        switch (operation)
        {
        //------calculating the requested equation for inputs-------------
        //-------at the same time printing the results on screen-----------
        case'+':
            cout<<"The addition of two numbers ("<<num1<<","<<num2<<"):";
            cout<<num1+num2<<endl;
            break;
        case'-':
            cout<<"The substraction of two numbers ("<<num1<<","<<num2<<"):";
            cout<<num1-num2<<endl;
            break;
        case'*':
            cout<<"The multiplication of two numbers ("<<num1<<","<<num2<<"):";
            cout<<num1*num2<<endl;
            break;
        case'/':
            cout<<"The division of two numbers ("<<num1<<","<<num2<<"):";
            if(num2==0)
            {
                cout<<"not valid"<<endl;
            }
            cout<<(num1/num2)<<endl;
            break;
        case's':
            cout<<"The swap of two numbers ("<<num1<<","<<num2<<"):";
            swap(num1,num2);
            cout<<"1stnumber="<<num1<<"and 2nd number="<<num2<<endl<<endl;
            break;
        default:
            cout<<"unknown command"<<endl;

        }
        //----now once again the program will ask the user if want to continue or not
        cout<<"enter y or Y to continue:";
        cin>>redo;
        cout<<endl<<endl;
    }
    while(redo=='y'||redo=='Y');

    return 0;

}

31. By Angus๐Ÿ‘‘

Simple C++ Calculator by Angus๐Ÿ‘‘. Enter first number then the operator, after that the second number, all in different lines. ( Source )


#include <iostream>
using namespace std;

int main() {
    int first_num ;
    char operators ;
    int second_num ;
    cin>> first_num ;
    cin>> operators ;
    cin>> second_num ;
    
    if (operators == '+'){
        cout<< "you entered " <<first_num <<"+" <<second_num<<endl ;
        cout<<"calculated = "<<first_num + second_num;
        }
        else if (operators == '-'){
                cout<< "you entered " <<first_num <<"-" <<second_num<<endl ;
                cout<<"calculated = " <<first_num - second_num;
            }
        else if (operators == '*'){
                cout<< "you entered " <<first_num <<"*" <<second_num<<endl ;
                cout<< "calculated = "<<first_num * second_num;
            }
        else if (operators == '/'){
                cout<< "you entered " <<first_num <<"/" <<second_num<<endl ;
                cout<< "calculated = "<<first_num / second_num;
            }
        else{
            cout<<"error operation";
        }
        cout<<endl<<"Thank u for running my program"<<endl<<"If u liked please upvote";
    return 0;
    
}

32. By Arash

Made by Arash. Enter input in the format 1 + 1. All in different lines. ( Source )

#include <iostream>
#include <math.h>
#include <string>

using namespace std;
int main(){
    double a;
    string b;
    double c;
    cin >> a >> b >> c;
    if (b == "-"){
        cout << a << b << c << "=" << a - c;
    }
    if (b == "+"){
        cout << a << b << c << "=" << a + c;
    }
    if (b == "ร—"){
        cout << a << b << c << "=" << a * c;
    }
    if (b == "%"){
        cout << a << b << c << "=" << (c*a)/100;
    }
    if (b == "รท"){
        cout << a << b << c << "=" << a/c;
    }
    if (b == "โˆš"){
        cout << b << a  << "=" << sqrt(a);
    }
    if (b == "^"){
        cout << a << b << c << "=" << pow(a,c);
    }
    return 0;
}

33. By Piotr Wronka

Made by Piotr Wronka. Enter first number, operator then the second number. all in different lines. ( Source )


#include <iostream>

using namespace std;

int main()
{

    double  a;   
    char b;
    double  c;
    double  z;
   cin>>a;
   cin >> b;
   cin >> c;
   if (b == '+'){
   z = a + c;
   }
   if (b == '-'){
   z = a - c;
   }
   if (b == '/'){
   z = a / c;
   }
   if (b == '*'){
   z = a*c;
   }
   cout << z << endl;
}

34. By Denis_vitiaz55055

Made by Denis_vitiaz55055. The program supports 3 numbers and 2 operators. Enter the operation in one single line. ( Source )

#include <iostream>
using namespace std;

int main()                
{   
    int firstF = 0;
    double  x;
    double  y;
    double  z;
    //your numbers^
    double  a;
    double  b;
    char func;
    char func2;
    cin>>x>>func>>y>>func2>>z;
    if(func2 == '*' or func2 == '/' or func2 =='^')
    {
    firstF = 1;
    }
    else {
    firstF = 0;   
    }
    if(firstF == 0) {
    switch (func) {
  case '+':
    a=x+y;
    break;
  case '-':
    a=x-y;
    break;
  case '*':
    a=x*y;
    break;
  case '/':
    a=x/y;
    break;
  case '^':
  for(int counter=1;counter<y;counter++)
  {
  x=x*x;
  }
    a=x;
    break;
    }
    switch (func2) {
  case '+':
    b=a+z;
    break;
  case '-':
    b=a-z;
    break;
  case '*':
    b=a*z;
    break;
  case '/':
    b=a/z;
    break; 
  default:
    b=a;
    break;
} 
}
else {
    switch (func2) {
  case '+':
    a=y+z;
    break;
  case '-':
    a=y-z;
    break;
  case '*':
    a=y*z;
    break;
  case '/':
    a=y/z;
    break;
  case '^':
  for(int counter;counter<z;counter++)
  {
  y=y*y;
  }
    a=y;
    break;
    }
    switch (func) {
  case '+':
    b=x+a;
    break;
  case '-':
    b=x-a;
    break;
  case '*':
    b=x*a;
    break;
  case '/':
    b=x/a;
    break;
} 
}
cout<<b;  
}

35. By leo Goncalves

C++ Calculator by leo Goncalves. Enter the operation in single line. ( Source )


#include <iostream>
#include <math.h>
using namespace std;

int main() {

    double num1;
    double num2;
    char op;
    
    cin >> num1 >> op >> num2;
    
    switch (op) {
        case '+':
           cout << num1 << '+' << num2 << '=' << num1 + num2; 
        break;
        
        case '-':
           cout << num1 << '-' << num2 << '=' << num1 - num2;
        break;
        
        case '/':
            if (num2 == 0){
                cout << "cannot divide by 0";
            } else {
                cout << num1 << '/' << num2 << '=' << num1 / num2;
            }
       break;
        
        case '*':
           cout << num1 << '*' << num2 << '=' << num1 * num2;
        break;
        
        case '^':
           cout << num1 << '^' << num2 << '=' << pow(num1, num2 );
       break;
       
        case 'e':
            cout << num1 << 'e' << num2 << '=' << num1 * pow( 10, num2 );
       break;
        
        default:
        cout << "invalid operation";

    }


/* trying to develop this to doing square rutes*/

    return 0;
}

36. By Zarina Maturaimova

Made by Zarina Maturaimova. Enter first number and second number to get the output of the operation using different operators. ( Source )

// My easy calculator
#include <iostream>

using namespace std;

 int main()
 {
 float num_1, num_2, sum, c, d;
 
 //Calculator name
  cout <<"Calculator 3000\n";
  
  //You enter the first number
  cout << "\nYour 1 number = x";
   cin >> num_1;
 
  cout << "\n";
  
//You enter the second number
   cout << "\nYour 2 number = y ";
    cin >> num_2;
   

 cout << "\n\nYour sum: ";
   sum = num_1 + num_2;
 cout << num_1 << "+" << num_2 << "=" << sum;
 

  cout << "\n\nYour division: ";
   c=num_1/num_2;
  cout << num_1 << "/" << num_2 << "=" << c;
  

  cout << "\n\nYour subtraction: ";
   d=num_1-num_2;
  cout << num_1 << "-" << num_2 << "=" << d;
  
 
  cout << "\n\nYour Multiplication: ";
   c=num_1*num_2;
  cout << num_1 << "*" << num_2 << "=" << c;
  
  return 0;
}

37. By Christoph

Made by Christoph. Enter operation in different lines, first enter first number then operator then the second number. ( Source )

#include <iostream>
#include <string>
using namespace std;


int main() {
    float a;
    float b;
    float ergebnis;
    std::string x;
    int d;
    cin >> a;
    cin >> x;
    cin >> b;
    
    if(x == "+"){
        d = 1;
    }
    else if(x == "*"){
        d = 2;
    }
    else if(x == "-"){
        d = 3;
    }
    else if(x == "/"){
        d = 4;
    }

    switch(d){
       case 1:
         ergebnis = a + b;
         cout << "The result of "<< a << " + " << b << " is " << ergebnis <<".";
         break; 
    case 2:
         ergebnis = a * b;
         cout << "The result of "<< a << " * " << b << " is " << ergebnis<<".";
         break;
    case 3:
         ergebnis = a - b;
         cout << "The result of "<< a << " - " << b << " is " << ergebnis<<".";
         break;
    case 4:
         ergebnis = a / b;
         cout << "The result of "<< a << " / " << b << " is " << ergebnis<<".";
         break;
    }
   
    return 0;
}

38. By Prabha_I

Made by Prabha_I. Give the one input and give space and give another input (i.e;34 12). ( Source )


#include <iostream>
using namespace std;
int main(){
long int a,b,d,i,sum=0;
cin>>a;
cin>>b;
d=b;
switch(1){
case 1://addition
sum=a-(-b);
cout<<a<<"+"<<b<<"="<<sum<<endl;

case 2:
sum=0;               //for subtraction
if(a>b&&a<0&&b<0||a>0&&b>0&&a>b||a>0&&b<0){

for(i=b;i<a;i++){
    sum=sum+1;
}
cout<<a<<"-"<<b<<"="<<sum<<endl;
}
else if(a<0&&b<0&&b>a||a>0&&b>0&&b>a||a<0&&b>0){
  for(i=a;i<b;i++){
      sum=sum+1;
  }
  cout <<a<<"-"<<b<<"="<<"-"<<sum<<endl;  
}
else if(a=b){
    cout<<a<<"-"<<b<<"="<<"0"<<endl;
}
case 3:                 //for multiplication
sum=0;
b=d;
if(a>0&&b>0||a<0&&b<0){
if(b>0){
while(b>0){
    sum=a+sum;
    b--;
}
cout<<a<<"*"<<d<<"="<<sum<<endl;}
else if(b<0){
while(b<0){
    sum=a+sum;
    b++;
}cout<<a<<"*"<<d<<"="<<-sum<<endl;    
}}
else if(a<0&&b>0||a>0&&b<0){
if(b>0){ while(b>0){
    sum=sum+a;
    b--; 
 }
 cout<<a<<"*"<<d<<"="<<sum<<endl;   
}else if(b<0){
    while(b<0){
        sum=sum+a;
        b++;
    }cout<<a<<"*"<<d<<"="<<-sum<<endl;
}}
case 4:                        //for division
sum=0;
b=d;
if(a>b&&a>0&&b>0||b>a&&a<0&&b<0){
    if(a>b){
        for(i=a;i>=b;i--){
        if(i%b==0){
            sum=sum+1;}
        }
        cout<<a<<"/"<<d<<"="<<sum<<endl;}
else if(b>a){
for(i=-a;i>=-b;i--){
if(i%b==0){
sum=sum+1;
    }
}cout<<a<<"/"<<b<<"="<<sum<<endl;
    
}}
else if(a>0&&b<0&&a>-b||a<0&&b>0&&-a>b){
if(a>-b){
    for(i=a;i>=-b;i--){
        if(i%b==0){
            sum=sum+1;
        }
    }cout<<a<<"/"<<b<<"="<<-sum<<endl;}
    else if(-a>b){
        for(i=-a;i>=b;i--){
            if(i%b==0){
                sum=sum+1;
            }
        }cout<<a<<"/"<<b<<"="<<-sum<<endl;
    }
}
else if(a>0&&b>0&&a<b||a<0&&b<0&&a>b||a>0&&b<0&&a<-b||a<0&&b>0&&-a<b){
    cout<<a<<"/"<<b<<"="<<"0"<<endl;
}
}cout<<endl<<"If any wrong answers....please comment ...."<<endl<<endl<<"only integers";
return 0;
}

39. By Baraa AB

C++ Calculator by Baraa AB. Enter the operation in one single line, first the operator then the two numbers, give space between operator and numbers. ( Source )


# include <iostream>
using namespace std;

int main()
{
    char op;
    float num1, num2;

    cout << "Enter operator either + or - or * or /: ";
    cin >> op;

    cout << "Enter two operands: ";
    cin >> num1 >> num2;

    switch(op)
    {
        case '+':
            cout << num1+num2;
            break;

        case '-':
            cout << num1-num2;
            break;

        case '*':
            cout << num1*num2;
            break;

        case '/':
            cout << num1/num2;
            break;              

        default:
            // If the operator is other than +, -, * or /, error message is shown
            cout << "Error! operator is not correct";
            break;
    }

    return 0;
}

40. By STRIKER

Made by STRIKER. Input example 5*2 or 9/5 or 2,6*8and so on use coma instead of decimal point. ( Source )


#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;

float add (float x, float y){
    return x+y;
}
float sub (float x, float y){
    return x-y;
}
float mul (float x, float y){
    return x*y;
}
float div (float x, float y){
    return x/y;
}
float con(string s){
    float n=0; int q=0;
    for (int i=0; i<s.length(); i++){
        if (int(s[i])==44){
            q=s.length()-i; q--; continue; 
        }
        n=n*10+(int(s[i])-48); }
        n/=pow(10,q);
    return n;
}
int main(){
    float x,y;
    int k,index;
    string s,sf,ss;
    cin>>s;
    sf=""; ss="";
    for (int i=0; i<s.length(); i++){
        if (int(s[i])==42 || int(s[i])==43 || int(s[i])==45 || int(s[i])==47){
             index=i; k=int(s[i]);}
    }
    for (int i=0; i<index; i++){
        sf+=s[i];
    }
    for (int i=index+1; i<s.length(); i++){
        ss+=s[i];
    }
    x=con(sf);
    y=con(ss);
    switch(k){
        case 42: cout<<s<<"="<<mul(x,y); break;
        case 43: cout<<s<<"="<<add(x,y); break;
        case 45: cout<<s<<"="<<sub(x,y); break;
        case 47: cout<<s<<"="<<div(x,y); break;
}
    return 0;
}

41. By Param

Made by Param. Enter the two numbers of the operation in one single line without the operator and with spaces in between the numbers. ( Source )

#include <iostream>
using namespace std;

int main() {
    int a,b;
    cout<<"calculator 1.0"<<endl;
    cout<<"----------------"<<endl;
    cin>>a>>b;
    cout<<"sum of "<<a <<" and "<<b<<" is "<<a+b<<endl;
    cout << "subtraction is "<<a-b<<endl;
    cout << "multication is "<<a*b<<endl;
    try {
    if(b==0) throw 0;
    cout << "divison is "<< (float)a/b<<endl;
    }
    catch (...)
    {
       cout <<"divide by zero error" <<endl;
    }
    return 0;
}

42. By Yamin Mansuri

Made by Yamin Mansuri. Enter the operation in one single line without spaces in between the numbers and operator. ( Source )

#include <iostream>

using namespace std;

int main() {

         float x , y ;
         
         char z ;
        
         cin >> x ;
         
         cin >> z ;
         
         cin >> y ;
            
             switch (z) {
            
             case '+' :
             
              cout << x << '+' << y << '=' << x+y ;
             
             break ;
             
             case '-' : 
             
             cout << x << '-' << y << '=' << x-y ;
             
             break ;
             
             case '*' :
             
             cout << x << '*' << y << '=' << x*y ;
             break ;
             
             case '/' : if ( y == 0) { 
             
             cout << "error" ;
           
             }
             
             else {
             
             cout << x << '/' << y << '=' << x/y ;}
              }   
       
    return 0;
    }

43. By Hrishikesh Kulkarni

C++ Calculator by Hrishikesh Kulkarni. Enter your input in this way first enter Integer1 then Integer2  after that 1. If addition  2. If Difference  3. If multiplication. ( Source )


#include<iostream>
using namespace std;
int main() 
{     
     int  a,b,c;
     char ch;
 cout << "SIMPLE CALCULATOR\n";
 cout << "\n Enter Two Integers \n:";
 cin >> a ;
 cin >> b ;
 cout << "\nSelect your choice :";
 cout << "+.Addition \n - .Difference";
 cout << "\n *.Multipication";
 cin >> ch ;
 cout << "\n";
 switch (ch)
 {
     case '+': c=a+b;
             cout << c;
             break;
     case '-': c=a-b;
             cout << c;
             break;
     case '*': c=a*b;
             cout << c;
             break;
   default : cout << "Invalid Choice";  
 }
 return 0;
}

44. By Time yyyf

Made by Time yyyf. Enter operation in single line without spaces. ( Source )

#include <iostream>
using namespace std;
#include <math.h>
int main() {
char  x;
double a;
double b;
cin >> a;
cin >> x;
cin >> b;
switch (x){
    case '+':
    cout <<a<<'+'<<b<<'='<< a+b;
    break;
    case '-':
    cout <<a<<'-'<<b<<'='<< a-b;
    break; 
    case '/':
    cout <<a<<'/'<<b<<'='<< a/b;
    break;
    case '*':
    cout <<a<<'*'<<b<<'='<< a*b;
    break;
}

    return 0;
    }

45. By Artashes

Made by Artashes. Enter operation in single line without any spaces in between operator and number. ( Source )

#include <iostream>
using namespace std;

int main()
{
    int a,b;
    char x;
    cin >> a >> x >> b;
    switch (x) {
        case '+':
            cout << a + b;
            break;
        case '-':
            cout << a - b;
            break;
        case '*':
            cout << a * b;
            break;
        case '/':
            if (b == 0){
            cout << "Error";
            break;
            }
            cout << a / b;
            break;
        default:
            cout << "ERROR!";
    }

    return 0;
}

46. By Frost

Made by Frost. Enter 2 no’s and also your choice at the first time only, each separated by space or on new lines, and check the output. ( Source )

Enter two nos: 5 5
Enter your choice: 1
1.Add
2.Subtract
3.Multiply
4.Divide
5.Modulus

Addition is:10
#include <iostream>
using namespace std;

int main() {

int a,b,c,choice;

cout<<"Enter two nos:\n";
cin>>a>>b;

cout<<"Enter your choice:\n";

cout<<"1.Add\n2.Subtract\n3.Multiply\n4.Divide\n5.Modulus\n\n";
cin>>choice;

switch(choice){

    case 1:
    c=a+b;
    cout<<"Addition is:"<<c<<endl;
    break;
    
    case 2:
    c=a-b;
    cout<<"Subtraction is:"<<c<<endl;
    break;
    
    case 3:
    c=a*b;
    cout<<"Multiplication is:"<<c<<endl;
    break;
    
    case 4:
    c=a/b;
    cout<<"Division is:"<<c<<endl;
    break;
    
    case 5:
    c=a%b;
    cout<<"Modulus is:"<<c<<endl;
    break;
    
    default:
    cout<<"Invalid choice!";
}
    return 0;
}

47. By Andrew

Made by Andrew. ( Source )

Enter number X 
Enter second number Y 
X = 10
Y = 10
MAIN MENU
=============
1.Addition 
2.Substraction 
3.Multiplication
4.Division
Choice  = 3
Quotient=100
#include <iostream>
#include <stdio.h>
#include <cstdlib>
using namespace std;
float x,y;
int choice;


int main() {

 
    cout <<"Enter number X "<<endl;
    cin>>x;
    cout <<"Enter second number Y "<<endl;
    cin>>y;
    cout<<"X = "<<x<<endl;
    cout<<"Y = "<<y<<endl;


      cout<<"MAIN MENU"<<endl;
      cout<<"============="<<endl;
      cout<<"1.Addition "<<endl;
      cout<<"2.Substraction "<<endl;
      cout<<"3.Multiplication"<<endl;
      cout<<"4.Division"<<endl;
      
    
      cin>>choice;
      cout<<"Choice  = "<<choice<<endl;
      
      switch (choice)
      { case 1 : 
        cout<<"Sum="<<x+y;
        break;
        case 2 :
        cout<<"Odds ="<<x-y;
        break;
        case 3 :
        cout <<"Quotient="<<x*y;
        break ;
        case 4 :
        if(y==0)
        cout<<"Do not divide by zero"<<endl;
        else cout <<"ratio = "<<x/y;
        break;
        
       }
       

    return 0;
}

48. By Marouane Krizi

Made by Marouane Krizi. ( Source )

3+2
5
 try again please 
#include <iostream> 
using namespace std ;
int main()
{
     int first_number ;
     int second_number ;
cin >> first_number ;
cin >> second_number ;
 cout << first_number + second_number  << endl ;
  cout << " try again please " ;
   return 0 ;
cout << first_number * second_number << endl ;
cout << " try again please " ;
 return 0 ;
cout << first_number - second_number << endl ;
cout << " try again please " ;
  return 0 ;

}

49. By salman

Made by salman. ( Source )

Options : 
Enter 'add' to add two numbers : 
Enter 'sub' to sub two numbers : 
Enter 'mul' to mul two numbers : 
Enter 'div' to div two numbers : 
Enter 'quit' to quit the calculator : 
add
Enter the first number : 20
Enter another number : 20
Answer after addition : 40
#include <iostream> 
#include <cstring> 
using namespace std; 
int main(){     
    float a,b,c;     
    char i[3];     
    do{     cout<<"Options : \n";     
    cout<<"Enter 'add' to add two numbers : \n";     
    cout<<"Enter 'sub' to sub two numbers : \n";     
    cout<<"Enter 'mul' to mul two numbers : \n";     
    cout<<"Enter 'div' to div two numbers : \n";     
    cout<<"Enter 'quit' to quit the calculator : \n";     
    cin>>i;         
        if (i[0] == 'q') {         
        break;         }         
        else if (i[0] == 'a'){         
        cout<<"Enter the first number : \n";                               
        cin>>a;         
        cout<<"Enter another number : \n";         
        cin>>b;         
        c = a + b;         cout<<"Answer after addition : "<<c<<"\n\n";         }         
        else if (i[0]=='s'){         
        cout<<"Enter the first number : \n";         
        cin>>a;        
        cout<<"Enter another number : \n";         
        cin>>b;         
        c = a - b;         
        cout<<"Answer after subtraction : "<<c<<"\n\n";         }         
        else if (i[0]=='m'){       
        cout<<"Enter the first number : \n";         
        cin>>a;         
        cout<<"Enter another number : \n";         
        cin>>b;         
        c = a * b;         
        cout<<"Answer after multiplication : "<<c<<"\n\n";         }         
        else if (i[0]=='d'){         
        cout<<"Enter the first number : \n";                    
        cin>>a;         
        cout<<"Enter another number : \n";         
        cin>>b;         
        c = a / b;         
        cout<<"Answer after division : "<<c<<"\n\n";         }         
        else {         
        cout<<"Invalid input : \n\n";         
        }     
    }while(true); 
return 0;
}          

50. By XXXMATRIXXXX

Made by XXXMATRIXXXX. Enter number operator then number to get the output. ( Source )

4+4
4 + 4 = 8
#include <iostream>
#include <cmath>
#include <cfloat>

using namespace std;

void menu() {
    cout<<" _._._._._._._._._._._._._._._._._._._\n|      Welcome to my Calculator!      |\n|Here are some instructions:          | \n";
    cout<<"|  1)Enter first number, then the     |\n|     operation and second number     |";
    cout<<"\n|  2)Operation can be:                |\n|      (+,-,*,/,^ and %)              |\n";
    cout<<"|  3)Enjoy!                           |\n";
    cout<<"|_._._._._._._._._._._._._._._._._._._|\n\n";
}

void calculator(double num1, char operation, double num2) {
    switch(operation) {
    case('+'):
        if((num1+num2)<=DBL_MAX || (num1+num2)>=DBL_MIN) {
            cout<<num1<<" "<<operation<<" "<<num2<<" = "<<num1+num2<<"\n\n";
            break;
        } else {
            cout<<"Overflow occured! Try again.\n";
            break;
        }
    case('-'):
        if((num1-num2)<=DBL_MAX || (num1-num2)>=DBL_MIN) {
            cout<<num1<<" "<<operation<<" "<<num2<<" = "<<num1-num2<<"\n\n";
            break;
        } else {
            cout<<"Overflow occured! Try again.\n";
            break;
        }
    case('*'):
        if((num1*num2)<=DBL_MAX || (num1*num2)>=DBL_MIN) {
            cout<<num1<<" "<<operation<<" "<<num2<<" = "<<num1*num2<<"\n\n";
            break;
        } else {
            cout<<"Overflow occured! Try again.\n";
            break;
        }
        
    case('/'):
        if(num2!=0)
            cout<<num1<<" "<<operation<<" "<<num2<<" = "<<num1/num2<<"\n\n";
        else
            cout<<"Error! Division by 0 is not 8defined."<<"\n\n";
        break;
    case('^'):
        if(pow(num1, num2)<=DBL_MAX) {
            if(num1==0 && num2==0) {
                cout<<num1<<" ^ "<<num2<<"\nAnswer in C++ is 1, but it is not mathematicaly defined.\n";
                break;
            }
            else {
                cout<<num1<<" "<<operation<<" "<<num2<<" = "<<pow(num1, num2)<<"\n\n";
                break;
            }
        } else {
            cout<<"Overflow occured! Try again.\n";
            break;
        }
    case('%'):
        cout<<num1<<" "<<operation<<" "<<num2<<" = "<<(int)num1%(int)num2<<"\n\n";
        break;
    default:
        cout<<"You entered wrong operation, try again."<<"\n\n";
        break;
    }

}

int main() {
    double num1, num2;
    char operation;
    menu();
    cin>>num1>>operation>>num2;
    calculator(num1, operation, num2);
    
    return 0;
}

51. By Ashfiya Mumtaz Hassan

Made by Ashfiya Mumtaz Hassan. Program to perform various arithmetic operations using switch statement. 3 inputs required in the following format: operand operator operand Eg.1 + 2 for operations involving 3 operands. To find the square root of a number, type in an operand and s and to find the cube root of a number type in an operand and c. ( Source )

Enter the expression: 7+7
Result = 14
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    float num1, num2, result=0;
    char optr;
    
    cout<<"Enter the expression:"<<endl;
    cin>>num1>>optr>>num2;
    switch(optr)
    {
        case '+':  result=num1+num2;
                     break;
        case '-':  result=num1-num2;
                     break;
        case '*':  result=num1*num2;
                     break;
        case '/':  result=num1/num2;
                     break;
        case '%':  result=(int)num1%(int)num2; 
                     break;
        case '^':  result=pow(num1, num2);
                     break;
        case '>': result=(num1>num2); 
                     break;
        case '<': result=(num1<num2); 
                     break;
        case 's': result=sqrt(num1);
                     break;
        case 'c': result=cbrt(num1);
                     break;
        default: cout<<"Invalid operation"<<endl;
    }
    cout<<"Result = "<<result<<endl;
    
    return 0;
}

52. By ConfiG

Made by ConfiG. ( Source )

Calculator v0.5 by ConfiG
1+1
1+1=2
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
    int A;
    int B;
    int result;
    char math;
    srand(time(0));
    cout << "Calculator v0.5 by ConfiG" << endl;
    cin >> A >> math >> B;
    switch (math) {
        case '+':
        result = A + B;
        cout << A << "+" << B << "=" << result << endl;
        break;
        case '-':
        result = A - B;
        cout << A << "-" << B << "=" << result << endl;
        break;
        case '*':
        result = A * B;
        cout << A << "*" << B << "=" << result << endl;
        break;
        case '/':
        result = A / B;
        cout << A << "/" << B << "=" << result << "(" << A % B << ")" << endl;
        break;
        case '?':
        cout << "Your random number from " << A << "to" << B << ": " << (rand()%(B-A+1))+A << endl;
        break;
        default:
        cout << "Error!" << endl;
        break;
    }
    return 0;
}

53. By Shimon

Made by Shimon. ( Source )

10+10
20
#include <iostream>
using namespace std;

int main() {
double a;
double b;
char c;
cin >> a;
cin >> c;
cin >> b;
	switch(c){
		case '+': {
			cout << a + b << endl;
		}
		break;
		case '-': {
			cout << a - b << endl;
		}
		break;
		case '/': {
			cout << a / b << endl;
		}
		break;
		case '*': {
			cout << a * b << endl;
		}
		break;
		default:
		cout << "Unknown operator" << endl;
	}
	return 0;
}

54. By Redi Marku

Made by Redi Marku. Just put in the input numbers and operator that you want to calculate. Example (3+8) or (7*7) etc. ( Source )

3+1
3+1=4

Try again
#include <iostream>
using namespace std;

int main() {
   
    int a, b;
    char op,re;
      
      cin>>a;
      cin>>op;
      cin>>b;
      
      do{
          switch (op){
             
             case'+':
                 cout<<a<<"+"<<b<<"="<<a+b
                     <<endl;
                break;
            
             case'-':
                 cout<<a<<"-"<<b<<"="<<a-b
                     <<endl;
                break;
            
             case'*':
                 cout<<a<<"*"<<b<<"="<<a*b
                     <<endl;
                break;
             
             case '/':
                 cout<<a<<"/"<<b<<"="<<a/b
                     <<endl;
                break;
             
             default :
                 cout<<"Your input is not correct, try to calculate something (example. 7+3)."
                     <<endl;
                
              
          }
          cout<<endl;
          cout<<"Try again";
          cin>>re;
          cout<<endl;
          
      }while(re=='y');
      
      
    return 0;
}

55. By Red Ender

Made by Red Ender. ( Source )

1
+
1
2
#include <iostream>
using namespace std;
    
int main () 
{
    int a;
    string  number;
    int b;
    cin>> a;
    cin>> number ;
    cin>> b;
    if(number =="+") {
    cout<< a + b;}
    if (number =="-") {
    cout<< a - b;}
    if (number =="*") {
    cout<< a * b;
    }
    if (number =="/") {
    if (b==0) {
    cout<< "zero error 666 "<<endl;
    int i=0;
    while (i<=362) {
    cout<< "error "<<endl;
    i++;
    }
    }
    else {
    cout<< a/b;}
    }
    if (number =="%") {
    cout<< a%b;
    }
    if (true) {
    if (number == "/%") {
    double  p=a;
    double r=b;
    cout<< p/r;}
    }
    if (number =="**") {
    int z=1;
    int n=a;
    while (z<b)
    {
        a=a*n;
        z++;
    }
    cout<<a;
    }
    
    
    return 0;
}

56. By Kuchiki

Made by Kuchiki. ( Source )

1+2
resulatat3
#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;
    int addition(int a,int b)
    {int result1=(a+b);
    return result1;}
    
      int souss(int a,int b)
    {int result2=(a-b);
    return result2;}
     
           int multi(int a,int b)
    {int result3=(a*b);
    return result3;}


         int dev(int a,int b)
    {int result4=(a/b);
    return result4;}
    
        
main()
{
    int a;
    char c;
    int b;
    int result1,result2,result3,result4;
    loop:
    cout<<" "  <<" "   << " "<< endl;
    cin>>a;
    cin>>c;
    cin>>b;
     
   result1= addition(a,b);
   result2= souss(a,b);
   result3= multi(a,b);
    result4= dev(a,b);
    

         switch (c) 
        {
          case '+' :
       cout<<" resulatat"<<result1<<endl;
       break;
       case '-':
       cout<<" resulatat"<<result2<<endl;
       break;
       case '*':
       cout<<" resulatat"<<result3<<endl;
        break;
        case '/' :
        cout<<" resulatat"<<result4<<endl;
        break;
        default :
        cout<<" errrrrr"<<endl;
        }
    
    
    goto loop;

system("pause");
    return 0;
}