fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main() {
  5. long double a, b, sum;
  6. char z;
  7. cin >> a >> z >> b;
  8. if (z == '+') {
  9. sum = a + b;
  10. } else if (z== '-') {
  11. sum = a - b;
  12. } else if (z == '*') {
  13. sum = a * b;
  14. } else if (z == '/') {
  15. if (b==0){
  16. cout << "You can't divide by zero"<< endl;
  17. return 0;
  18. }
  19. sum = a / b;
  20. } else if (z == '%') {
  21. if (b==0){
  22. cout << "You can't take remainder of the division by zero"<< endl;
  23. return 0;
  24. }
  25. sum= fmod (a,b);
  26. }else if (z == '^') {
  27. sum=pow(a,b);
  28. }
  29. cout << a <<" "<< z <<" "<< b << " = " << sum << endl;
  30. return 0;
  31. }
Success #stdin #stdout 0s 3416KB
stdin
5.3 % 0
stdout
You can't take remainder of the division by zero