-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvanced.cpp
28 lines (27 loc) · 866 Bytes
/
advanced.cpp
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
#include "argparse.h"
#include <iostream>
#include <cmath>
auto main(int argc, char * argv[]) -> int
{
auto parser = argparse::ArgumentParser();
parser.add_argument("x").type<int>().help("the base");
parser.add_argument("y").type<int>().help("the exponent");
parser.add_argument("-v", "--verbosity").type<int>().default_(0);
auto parsed = parser.parse_args(argc, argv);
auto base = parsed.get_value<int>("x");
auto exp = parsed.get_value<int>("y");
auto answer = std::pow(base, exp);
auto verbosity = parsed.get_value<int>("verbosity");
if (verbosity >= 2)
{
std::cout << base << " to the power " << exp << " equals " << answer << '\n';
}
else if (verbosity >= 1)
{
std::cout << base << "^" << exp << " == " << answer << '\n';
}
else
{
std::cout << answer << '\n';
}
}