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