-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex2.cpp
More file actions
25 lines (24 loc) · 818 Bytes
/
complex2.cpp
File metadata and controls
25 lines (24 loc) · 818 Bytes
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
#include "argparse.hpp"
#include <iostream>
auto main(int argc, char * argv[]) -> int
{
auto parser = argparse::ArgumentParser();
parser.add_argument("square").help("display a square of a given number").type<int>();
parser.add_argument("-v", "--verbosity").help("increase output verbosity").type<int>();
auto parsed = parser.parse_args(argc, argv);
auto value = parsed.get_value<int>("square");
auto answer = value * value;
auto verbosity = parsed.get("verbosity");
if (verbosity && verbosity.get<int>() == 2)
{
std::cout << "the square of " << value << " equals " << answer << '\n';
}
else if (verbosity && verbosity.get<int>() == 1)
{
std::cout << value << "^2 == " << answer << '\n';
}
else
{
std::cout << answer << '\n';
}
}