Program to make a simple Calculator.

Definition:-A calculator is a device that performs arithmetic operations on numbers. The simplest calculators can do only addition, subtraction, multiplication, and division. More sophisticated calculators can handle exponential operations, roots, logarithm s, trigonometric functions, and hyperbolic functions. Internally, some calculators actually perform all of these functions by repeated processes of addition.

Program:-

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
 #include<stdlib.h>
 void main()
{
 clrscr();
 float a, b, res;
 char choice, ch;
 do
 {
 cout<<"1.Addition\n";
 cout<<"2.Subtraction\n";
 cout<<"3.Multiplication\n";
 cout<<"4.Division\n";
 cout<<"5.Exit\n\n";
 cout<<"Enter Your Choice : ";
 cin>>choice;
switch(choice)
{
case '1' : cout<<"Enter two number : ";
                cin>>a>>b; res=a+b;
                cout<<"Result = "<<res;
                break;
case '2' : cout<<"Enter two number : ";
                cin>>a>>b; res=a-b; cout<<"Result = "<<res;
                break;
case '3' : cout<<"Enter two number : ";
               cin>>a>>b; res=a*b;
               cout<<"Result = "<<res;
               break;
case '4' : cout<<"Enter two number : ";
              cin>>a>>b;
              res=a/b;
              cout<<"Result = "<<res;
              break;
case '5' : exit(0);
              break;
 default : cout<<"Wrong Choice..!!"; break;
 }
 cout<<"\n------------------------------------\n";
 }while(choice!=5 && choice!=getchar());
 getch();
}

Output:-





Post a Comment

0 Comments