Two numbers are entered and operation (sum,differnce,multiply,divide) to be performed is asked by the user. result is given according to the operation entered by user. (+,-,*,/)
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
- #include<iostream.h>
- #include<conio.h>
- void main()
- {
- clrscr();
- int s;
- float a,b,r;
- char op;
- cout<<"Please Enter a no.: ";
- cin>>a;
- cout<<"Please Enter operation to be performed.:(+,-,*,/,%) ";
- cin>>op;
- cout<<"Please Enter another no.: ";
- cin>>b;
- //Coding by: Snehil Khanor
- //http://WapCPP.blogspot.com
- switch (op)
- {
- case '+':
- r=a+b;
- break;
- case '-':
- r=a-b;
- break;
- case '*':
- r=a*b;
- break;
- case '/':
- r=a/b;
- break;
- default:
- cout<<"Please enter Correct operation :)";
- s=0;
- }
- if(s)
- cout<<a<<op<<b<<"="<<r;
- getch();
- }
1 comments:
Hy, am new here!i was searching for how to create a calculator and i discover your site,in fact is is highly fascinating,am really impressed by this work of yours with some examples that are simple to understand.but i found an error which you did not include based on line "12" which is:
cout<<"please enter operation to be performed .:(+,-,*,/,%)
so what i added was cout<<"please enter operation to be performed .:(+,-,*,/,%)";
thanks.
Post a Comment