/****************************************************************************** * This program computes the roots of quadratic equations * of the form Ax^2 + Bx + C = 0 * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ #undef NDEBUG #include "Utils.hpp" #include #include #include #include #include #include #include std::locale utf8loc(std::locale(), new std::codecvt_utf8); using namespace std; int main(int argc, char **argv) { setlocale(LC_ALL, "en_US.UTF-8"); wcout.imbue(utf8loc); wcin.imbue(utf8loc); if (argc != 4) { wcout << fmt::format(L"Syntax: {0:s} a b c", Utils::UTF8_to_wstring(argv[0])) << endl; exit(1); } double const A = Utils::stodWithDefault(Utils::UTF8_to_wstring(argv[1]), 0); double const B = Utils::stodWithDefault(Utils::UTF8_to_wstring(argv[2]), 0); double const C = Utils::stodWithDefault(Utils::UTF8_to_wstring(argv[3]), 0); double discriminant = B * B - 4. * A * C; discriminant = sqrt(discriminant); double root1 = (-B + discriminant) / (2. * A); double root2 = (-B - discriminant) / (2. * A); wcout << L"root #1: " << root1 << endl; wcout << L"root #2: " << root2 << endl; return 0; }