fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. string operation;
  6. double val1,val2;
  7. cout<<"Please enter an operation(+,-,*,/,plus,minus,mul,div) followed by two floating-point values separated by a space: ";
  8.  
  9.  
  10. while(cin>>operation>>val1>>val2) {
  11.  
  12. double res;
  13.  
  14. if(operation == "plus" || operation=="+") res=val1+val2;
  15. else if(operation == "minus"|| operation=="-") res=val1-val2;
  16. else if(operation == "mul" || operation=="*") res=val1*val2;
  17. else if(operation == "div" || operation=="/") {
  18.  
  19. if(val2==0)
  20. {
  21.  
  22. cout<<"Error! Trying to divide by zero!";
  23.  
  24. }
  25.  
  26. else{
  27. res=val1/val2;}
  28. }
  29.  
  30. cout<<val1<<operation<<val2<<"=="<<res<<endl;
  31. cout<<"please try again"; }
  32. cout<<"exit cuz of bad input";
  33. }
Success #stdin #stdout 0s 3280KB
stdin
/
8
0
stdout
Please enter an operation(+,-,*,/,plus,minus,mul,div) followed by two floating-point values separated by a space: Error! Trying to divide by zero!8/0==-4.75195e-42
please try againexit cuz of bad input