Write a program to make a simple calculator

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 :)



  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int s;
  7. float a,b,r;
  8. char op;
  9. cout<<"Please Enter a no.: ";
  10. cin>>a;
  11. cout<<"Please Enter operation to be performed.:(+,-,*,/,%) ";
  12. cin>>op;
  13. cout<<"Please Enter another no.: ";
  14. cin>>b;
  15. //Coding by: Snehil Khanor
  16. //http://WapCPP.blogspot.com
  17. switch (op)
  18. {
  19. case '+':
  20. r=a+b;
  21. break;
  22. case '-':
  23. r=a-b;
  24. break;
  25. case '*':
  26. r=a*b;
  27. break;
  28. case '/':
  29. r=a/b;
  30. break;
  31. default:
  32. cout<<"Please enter Correct operation :)";
  33. s=0;
  34. }
  35. if(s)
  36. cout<<a<<op<<b<<"="<<r;
  37. getch();
  38. }

Check out this stream