C++ Program to make calculator using switch case and the program should continue as user wants
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float a,b,c;
char op,ch1;
do
{
cout<<"enter first number ::: ";
cin>>a;
cout<<"enter second number ::: ";
cin>>b;
cout<<"enter the operator ::: ";
cin>>op;
switch(op)
{ case '+': c=a+b;
cout<<"The Calculated result is ::: "<<c;
break;
case '-': c=a-b;
cout<<"The Calculated result is ::: "<<c;
break;
case '*': c=a*b;
cout<<"The Calculated result is ::: "<<c;
break;
case '/': c=a/b;
cout<<"The Calculated result is ::: "<<c;
break;
default:
cout<<"wrong operator used";
cin>>ch1;
}//switch statement close
cout<<"\nDo you want to continue(y/n) :: ";
cin>>ch1;
}while(ch1=='y' || ch1=='Y');
getch();
}
THE OUTPUT OF ABOVE PROGRAM WILL BE....
HERE IS THE VIDEO BY ME ::
#include<conio.h>
void main()
{
clrscr();
float a,b,c;
char op,ch1;
do
{
cout<<"enter first number ::: ";
cin>>a;
cout<<"enter second number ::: ";
cin>>b;
cout<<"enter the operator ::: ";
cin>>op;
switch(op)
{ case '+': c=a+b;
cout<<"The Calculated result is ::: "<<c;
break;
case '-': c=a-b;
cout<<"The Calculated result is ::: "<<c;
break;
case '*': c=a*b;
cout<<"The Calculated result is ::: "<<c;
break;
case '/': c=a/b;
cout<<"The Calculated result is ::: "<<c;
break;
default:
cout<<"wrong operator used";
cin>>ch1;
}//switch statement close
cout<<"\nDo you want to continue(y/n) :: ";
cin>>ch1;
}while(ch1=='y' || ch1=='Y');
getch();
}
THE OUTPUT OF ABOVE PROGRAM WILL BE....
HERE IS THE VIDEO BY ME ::
Comments
Post a Comment