Vous êtes sur la page 1sur 3

PROGRAM NO: 2

/*
Title: Calculator Designer
Name: Rinky Dutta
Roll no: A-14
*/
#include<iostream.h>
#include<conio.h>
void main()
{
char n,i= Y ; //declaring and initializing variables
float x y;
clrscr(); //for clearing the previously execut
ed code
do
{
cout<< Enter two numbers:<<endl;
cin>>x; //accepting values
cin>>y;
cout<< Signs for type of operations <<endl;
cout<< + for add <<endl
<< - for sub <<endl
<< * for multiply <<endl
<< / for division <<endl;
cin>>n;
switch(n)
{
case + : //for addition
{
float z;
z=x+y;
cout<< Addition is <<z<<endl;
break;
}
case - : //for subtraction
{
float z;
z=x-y;
cout<< Subtraction is <<z<<endl;
break;
}
case * : //for multiplication
{
float z;
z=x*y;
cout<< Multiplication is <<z<<endl;
break;
}
case / : //for division
{
float z;
if(y==0) //for checking whether divisor is zero or
not
{
cout<< Divisor cannot be zero. Enter a non-zero value: ;
cin>>y;
z=x/y;
cout<< Division is <<z<<endl;
}
break;
}
}
default: //for invalid entry of sign
{
cout<< You have entered wrong sign <<endl;
break;
}
}
cout<< Do you want to perform any other operation(Y/N) <<endl;
cin>>i;
}while(i== Y ); //while loop to perform a task number of times
getch(); //to get the values of operation
}

/*
OUTPUT:
Enter two numbers:
8
5
Signs for type of operations
+ for add
- or sub
* for multiply
/ for division
Addition is 13
Do you want to perform any other operation(Y/N)
Y
Enter two numbers:
15
5
Signs for type of operators
+ for add
- for sub
* for multiply
/ for division
Subtraction is 10
Do you want to perform any other operation(Y/N)
Y
Enter two numbers:9:58 AM 10/29/2009
41
5
Signs for type of operations
+ for add
- for sub
* for multiply
/ for division
*
Multiplication is 205
Do you want to perform any other operation(Y/N)
Y
Enter two numbers:
85
5
Signs for type of operations
+ for add
- for sub
* for multiply
/ for division
/
Division is 17
Do you want to perform another operation(Y/N)
N
*/

Vous aimerez peut-être aussi