Learn C++ beginer programs

July 8, 2009

Write a program to make a simple calculator

Filed under: calculator,cin,cout,else if,if,if else,switch — snehilkhanor @ 3:22 am
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. switch (op)
  16. {
  17. case ‘+’:
  18. r=a+b;
  19. break;
  20. case ‘-’:
  21. r=a-b;
  22. break;
  23. case ‘*’:
  24. r=a*b;
  25. break;
  26. case ‘/’:
  27. r=a/b;
  28. break;
  29. default:
  30. cout<<”Please enter Correct operation :) “;
  31. s=0;
  32. }
  33. if(s)
  34. cout<<a<<op<<b<<”=”<<r;
  35. getch();
  36. }

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.