/****************************************************************************** * This program computes NFL passer ratings. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ #undef NDEBUG #include "Utils.hpp" #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); try { wstring input_str; int attempts; input_str = Utils::prompt(L"Number of attempts: "); attempts = stoi(input_str); int completions; input_str = Utils::prompt(L"Number of completions: "); completions = stoi(input_str); int touchdown_passes; input_str = Utils::prompt(L"Number of touchdown passes: "); touchdown_passes = stoi(input_str); int interceptions; input_str = Utils::prompt(L"Number of interceptions: "); interceptions = stoi(input_str); int passing_yards; input_str = Utils::prompt(L"Number of passing yards: "); passing_yards = stoi(input_str); double const a = (completions / double(attempts) - 0.3) * 5.; double const b = (passing_yards / double(attempts) - 3.) * 0.25; double const c = touchdown_passes / double(attempts) * 20.; double const d = 2.375 - (interceptions / double(attempts) * 25.); double const RATING = (a + b + c + d) / 6. * 100.; wcout << fmt::format(L"Passer rating: {0:.1f}", RATING) << endl; } catch (invalid_argument ex) { wcout << wstring(L"Bad input! ") + Utils::exceptionMessage(ex) << endl; } catch (...) { wcout << L"Don't know what went wrong!" << endl; } return 0; }