The simple calculator….

this is the source code for a simple calculator.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float n1=0,n2=0,re=0;
char cho;
cout<<”Welcome to Calc basic \n”;
cout<<”Please enter the 1st number then space followed by arithmetic operator then space and second number \n”
<<”For eg: 1 + 2 and press enter key \n\n\n”;
cin>>n1>>cho>>n2;
switch (cho)
{
case ‘+’ :re=n1+n2;
break;
case ‘-’ :re=n1-n2;
break;
case ‘*’ :re=n1*n2;
break;
case ‘/’ :if (n2==0)
{
cout<<”Sorry division by zero is undefined”;
}
else
{
re=n1/n2;
}
break;
case ‘%’ :if (n2==0)
{
cout<<”Sorry division by zero is undefined”;
}
else
{
re=n1/n2;
cout<<”modulo is not defined for floats \n”;
}
break;
default :cout<<”you have entered an unusual operation\n”;
}
cout<<”your result of “<<n1<<cho<<n2<<” is “<<re;
getch();
}

Follow

Get every new post delivered to your Inbox.