Simple C++ Calculator Code Implementation

Leave a Comment
//Creating a simple calculator in C++
#include <iostream>
#include<stdlib.h>
using namespace std;
int main()
{
    float num1,num2;
//numbers "num1"and"num2"
    char op;
    cout<<"enter the statement:\n";
//asking the user for statement
    cin>>num1>>op>>num2;
    if (op== '+')
//condition for addition
        cout<<num1<<"+"<<num2<<"=" <<num1+num2<<endl;
    if (op=='-')
//condition for subtraction
        cout<<num1<<"-"<<num2<<"="<<num1-num2<<endl;
    if (op=='*')
//condition for multiplication
        cout<<num1<<"*"<<num2<<"=" <<num1*num2<<endl;
    if (op=='/')
//condition for division
        cout<<num1<<"/"<<num2<<"="<<num1/num2<<endl;
    system("pause");
    return 0;
}


ScreenShots:-
Example Of Division in C++ Calculator Code Implementation
Example Of Division in C++ Calculator Code Implementation

0 comments: