Program to calculate basic arithmetic operations.
Using Visual Studio 2015
===============================================================
#include<iostream>
using namespace std;
#include<conio.h>
void main()
{
char O;
float num1,num2,Multiplication,Addition,Subtraction,Division;
cout<<"enter First Number=";
cin>>num1;
cout<<"enter Second Number=";
cin>>num2;
cout<<"enter an operator=";
cin>>O;
switch (O)
{
case '+':
Addition=a+b;
cout<<"\nAddition="<<Addition;
break;
case '*':
Multiplication=a*b;
cout<<"\nMultiplication="<<Multiplication;
break;
case '/':
Division=a/b;
cout<<"\nDivision="<<Division;
break;
case '-':
Subtraction=a-b;
cout<<"\nSubtraction="<<Subtraction;
break;
default:
cout<<"\ninvalid input";
break;
}
_getche();
}
==============================================================
It is a program to calculate the basic arithmetic operations. In this case, 'Switch statement' is used.
The calculating operations are introduced in "char", because arithmetic operations are basically characters.
Comments
Post a Comment