W.A.P. C++

WAP | CPP | Programs in C++ | C++ Solutions

Snehil Khanor's Binary Log

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. }

1 comments:

kellkings October 9, 2013 at 1:06 AM  

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.

Search

About WAP C++

Here you'll find a wide range of programs' solution ranging from beginer level to advanced level.
All programs here are made, compiled and tested by me..and are running absolutely fine.. still if you find any bug in any program do let me know :)

Followers

Subscribe via email

Enter your email address:

Delivered by FeedBurner

my Binary Log

Blog Archive



eXTReMe Tracker