-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (40 loc) · 1.33 KB
/
Copy pathmain.cpp
File metadata and controls
50 lines (40 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "Calculator.h"
#include <iostream>
/*
App - Calculator.
The method of calculation - Revers Polish Notation.
More details about the algorithm https://habrahabr.ru/post/100869/
This calculator check error like:
"--1 + 2" double or more operands
"12,,1 - 1" double or more commas
"12..1 - 1" double or more dots
"((12.1 - 1)" double or more open parenthesis
"(12.1 - 1))" double or more closing parenthesis
"asd 12.1 - 1" incorrect elements
"1+1" without whitespaces
"1 + 1" one or more whitespaces
Author: Sizih Vladimir. 2016
*/
int main() {
std::cout << "\nWelcome! To exit, type \"exit\". \n" << std::endl
<< "Enter the expression: ";
std::cout.setf(std::ios::fixed, std::ios::floatfield); // floatfield set to fixed
std::cout.precision(2);
std::string _expression; // stores the expression
Calculator* calculator = new Calculator(); // the calculation expression
std::getline(std::cin, _expression);
while (_expression.compare("exit"))
{
try {
calculator->SetExpression(_expression);
std::cout << "Answer: " << calculator->GetAnswer() << std::endl;
}
catch (Exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
std::cout << "Enter the expression: ";
std::getline(std::cin, _expression);
}
delete calculator;
return 0;
}