Wednesday, 10 April 2013
program using functions to ask user enter to number and choice its option of mathematical operation to perform in a loop and loop only breaks if user enter exit option
#include<iostream.h>
#include<conio.h>
using namespace std;
int add(int,int);
int sub(int,int);
int mul(int,int);
int divi(int,int);
main()
{
int number,num1,sum,num2,i=1;
while(i>0)
{
cout<<"\n1. ADD NUMBERS"<<endl;
cout<<"2. SUBSTRAT NUMBERS"<<endl;
cout<<"3. MULIPLY NUMBERS"<<endl;
cout<<"4. DIVIDE NUMBERS"<<endl;
cout<<"5. EXIT"<<endl;
cout<<"\n Enter Your Choice :"<<endl;
cin>>number;
switch(number)
{
case 1:
{
cout<<"\nADDITION"<<endl;
cout<<"\nEnter 1st Number :"<<endl;
cin>>num1;
cout<<"Enter 2nd Number :"<<endl;
cin>>num2;
sum=add(num1,num2);
cout<<"\nAnswer = "<<sum<<endl;
break;
}
case 2:
{
cout<<"\nSUBSTRACTIN"<<endl;
cout<<"\nEnter 1st Number :"<<endl;
cin>>num1;
cout<<"Enter 2nd Number :"<<endl;
cin>>num2;
sum=sub(num1,num2);
cout<<"\nAnswer = "<<sum<<endl;
break;
}
case 3:
{
cout<<"\nMULTIPLICATION"<<endl;
cout<<"\nEnter 1st Number :"<<endl;
cin>>num1;
cout<<"Enter 2nd Number :"<<endl;
cin>>num2;
sum=mul(num1,num2);
cout<<"\nAnswer = "<<sum<<endl;
break;
}
case 4:
{
cout<<"\nDIVISION"<<endl;
cout<<"\nEnter 1st Number :"<<endl;
cin>>num1;
cout<<"Enter 2nd Number :"<<endl;
cin>>num2;
sum=divi(num1,num2);
cout<<"\nAnswer = "<<sum<<endl;
break;
}
case 5:
{
exit(0);
}
i++;
}
}
getch();
}
int add(int a, int b)
{
int d;
d=a+b;
return d;
}
int sub(int e, int f)
{
int g;
g=e-f;
return g;
}
int mul(int h, int i)
{
int j;
j=h*i;
return j;
}
int divi(int k, int l)
{
int m;
m=k/l;
return m;
}
Labels:
programs
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment