Wednesday, 10 April 2013
program 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;
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=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=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=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=num1/num2;
cout<<"\nAnswer = "<<sum<<endl;
break;
}
case 5:
{
exit(0);
}
i++;
}
}
getch();
}
Labels:
programs
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment