Skip to content

Commit

Permalink
Fehlerbehandlung für Beispielcode
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfehrs committed Jul 23, 2024
1 parent ddb3013 commit 2031b2f
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,33 @@ production code.

namespace zs = zollstock;

[[noreturn]] void argument_error()
{
std::cerr << "Invalid arguments\n"
<< "Usage: pcalc <wall thickness (cm)> <outer radius (cm)> <pipe length (m)>\n";

std::exit(1);
}

int main(int argc, char** argv)
{
// Calculation of a pipes material volume
// Checking arguments

if (argc != 4)
argument_error();

try
{
const zs::double_t<zs::cm> wall_thickness{ std::stod(argv[1]) };
const zs::double_t<zs::cm> outer_radius{ std::stod(argv[2]) };
const zs::double_t<zs::cm> length{ zs::double_t<zs::m>{ std::stod(argv[3]) } };
}
catch(const std::exception&)
{
argument_error();
}

const zs::double_t<zs::cm> wall_thickness{ std::stod(argv[1]) };
const zs::double_t<zs::cm> outer_radius{ std::stod(argv[2]) };
const zs::double_t<zs::cm> length{ zs::double_t<zs::m>{ std::stod(argv[3]) } };
// Calculation of a pipes material volume

const auto inner_radius = outer_radius - wall_thickness;
const auto outer_area = zs::pi * outer_radius * outer_radius;
Expand Down

0 comments on commit 2031b2f

Please sign in to comment.