From 4981c10e1d3fbdae15a3f2119cccd0039baca582 Mon Sep 17 00:00:00 2001 From: kimwalisch Date: Fri, 19 Feb 2021 14:05:10 +0100 Subject: [PATCH] Improve -q option #102 --- src/app/main.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/app/main.cpp b/src/app/main.cpp index d3b01058b..9b3081ac7 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -2,7 +2,7 @@ /// @file main.cpp /// @brief primesieve console application. /// -/// Copyright (C) 2018 Kim Walisch, +/// Copyright (C) 2021 Kim Walisch, /// /// This file is distributed under the BSD License. See the COPYING /// file in the top level directory. @@ -12,6 +12,7 @@ #include "cmdoptions.hpp" #include +#include #include #include #include @@ -60,7 +61,7 @@ void sieve(CmdOptions& opt) ps.sieve(); - const string text[6] = + const array labels = { "Primes: ", "Twin primes: ", @@ -73,9 +74,22 @@ void sieve(CmdOptions& opt) if (opt.time) printSeconds(ps.getSeconds()); + // Did we count primes & k-tuplets simultaneously? + int cnt = 0; for (int i = 0; i < 6; i++) if (ps.isCount(i)) - cout << text[i] << ps.getCount(i) << endl; + cnt++; + + for (int i = 0; i < 6; i++) + { + if (ps.isCount(i)) + { + if (opt.quiet && cnt == 1) + cout << ps.getCount(i) << endl; + else + cout << labels[i] << ps.getCount(i) << endl; + } + } } void nthPrime(CmdOptions& opt) @@ -106,7 +120,10 @@ void nthPrime(CmdOptions& opt) if (opt.time) printSeconds(ps.getSeconds()); - cout << "Nth prime: " << nthPrime << endl; + if (opt.quiet) + cout << nthPrime << endl; + else + cout << "Nth prime: " << nthPrime << endl; } } // namespace