Public paste
Undefined
By: rechnerjow | Date: Nov 4 2009 10:31 | Format: C++ | Expires: never | Size: 902 B | Hits: 874

  1. #include <iostream.h>
  2. int main()
  3.   {
  4.          double x, y, z;
  5.          char zeichen;
  6.          bool b;
  7.          cout << "         TASCHENRECHNER" << endl <<endl;
  8.          cout << "1. Operand:  " ;
  9.          cin >> x;
  10.          cout << "Operation:   " ;
  11.          cin >> zeichen;
  12.          cout << "2. Operand:  ";
  13.          cin >> y;
  14.          b = true;
  15.          switch (zeichen)
  16.                 {
  17.                 case '+': z = x + y; break;
  18.                 // break-Anweisung bewirkt Sprung zur 1. Anweisung
  19.                 // nach der switch-Anweisung
  20.                 case '-': z = x - y; break;
  21.                 case '*': z = x * y; break;
  22.                 case ':': case '/': z = x / y; break;
  23.                 default : cout << "Operation nicht durchfuehrbar"<< endl; b = false;
  24.                 }
  25.          if (b) cout << "Ergebnis:    " << z << endl;
  26.          return 0;
  27.   }
  28.  
  29. /* Testlaeufe:        
  30.  
  31.                         TASCHENRECHNER
  32.  
  33. 1. Operand:  17
  34. Operation:   *
  35. 2. Operand:  33
  36. Ergebnis:    561
  37.  
  38.            TASCHENRECHNER
  39.  
  40. 1. Operand:  1
  41. Operation:   #
  42. 2. Operand:  1
  43. Operation nicht durchfuehrbar
  44. */