Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int form();
  6. int sum();
  7. int slag();
  8.  
  9. int main() {
  10. try {
  11. cout << form() << endl;
  12. } catch (runtime_error err) {
  13. cout << err.what() << endl;
  14. }
  15. return 0;
  16. }
  17.  
  18. int form() {
  19. int res = sum();
  20. char ch;
  21. cin >> ch;
  22. if (ch != '.') throw runtime_error("Это не точка!");
  23. return res;
  24. }
  25.  
  26. int sum() {
  27. int a = slag();
  28. char ch;
  29. cin >> ch;
  30. if (ch == '+') return a + sum();
  31. if (ch == '-') return a - sum();
  32. cin.putback(ch);
  33. return a;
  34. }
  35.  
  36. int slag() {
  37. char ch;
  38. cin >> ch;
  39. if (ch == '(') {
  40. int a = sum();
  41. cin >> ch;
  42. if (ch != ')') throw runtime_error("Нет закрывающей скобки!!!");
  43. return a;
  44. }
  45. cin.putback(ch);
  46. int a;
  47. cin >> a;
  48. return a;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement