Skip to content

Commit f5cb1cf

Browse files
committed
feat: add main function to evaluate RPN expressions from command-line input
1 parent 84d136a commit f5cb1cf

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

ex01/main.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "RPN.hpp"
2+
3+
int main(int ac, char** av)
4+
{
5+
if (ac < 2) {
6+
std::cerr << "Error: Invalid number of arguments." << std::endl;
7+
return 1;
8+
}
9+
std::string expression;
10+
for (int i = 1; i < ac; ++i)
11+
{
12+
expression += av[i];
13+
if (i < ac - 1)
14+
expression += " ";
15+
}
16+
try {
17+
int result = RPN::evaluate(expression);
18+
19+
std::cout << "Result: " << result << std::endl;
20+
} catch (const std::exception &e) {
21+
std::cerr << e.what() << std::endl;
22+
return 1;
23+
}
24+
return 0;
25+
}

0 commit comments

Comments
 (0)