Advertisement
Guest User

07. Operations Between Numbers

a guest
Jun 26th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. int main(){
  7.  
  8. int n1, n2 ;
  9. cin >> n1 >> n2 ;
  10.  
  11. char sign ;
  12. cin >> sign ;
  13.  
  14. int result ;
  15.  
  16. if (sign == '+'){
  17. result = n1 + n2 ;
  18. if (result % 2 == 0){
  19. cout << n1 << " + " << n2 << " = " << result << " - even" << endl;
  20. }else {
  21. cout << n1 << " + " << n2 << " = " << result << " - odd" << endl;
  22. }
  23. }
  24. if (sign == '-'){
  25. result = n1 - n2 ;
  26. if (result % 2 == 0){
  27. cout << n1 << " - " << n2 << " = " << result << " - even" << endl;
  28. }else {
  29. cout << n1 << " - " << n2 << " = " << result << " - odd" << endl;
  30. }
  31. }
  32.  
  33. if (sign == '*'){
  34. result = n1 * n2 ;
  35. if (result % 2 == 0){
  36. cout << n1 << " * " << n2 << " = " << result << " - even" << endl;
  37. }else {
  38. cout << n1 << " * " << n2 << " = " << result << " - odd" << endl;
  39. }
  40. }
  41.  
  42.  
  43. /// Division !
  44.  
  45. if (sign == '/'){
  46. if (n2 == 0){
  47. cout << "Cannot divide " << n1 << " by zero" << endl;
  48. }else {
  49. double result = 1.0 * n1 / n2 ;
  50. cout.setf(ios::fixed);
  51. cout.precision(2);
  52. cout << n1 << " / " << n2 << " = " << result << endl;
  53. }
  54. }
  55.  
  56. /// div %
  57.  
  58. if (sign == '%'){
  59. if (n2 == 0){
  60. cout << "Cannot divide " << n1 << " by zero" << endl;
  61. }else {
  62. cout << n1 << " % " << n2 << " = " << n1 % n2 << endl;
  63. }
  64. }
  65.  
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement